-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTime.java
More file actions
99 lines (89 loc) · 2.05 KB
/
Time.java
File metadata and controls
99 lines (89 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
Adoga Haruna. SRN: 13000236
*/
/**
*
* @author ian
*/
/**
*Simple Date/Time class
*/
public class Time{
private int day;
private int month;
private int year;
private int hour;
private int minute;
private int sec;
/**
*Construct new Time with day as int, month as int, year as int, hour and minutes
* as int. Note that this class is very basic and does not check for "impossible"
* times.
*/
public Time (int day, int month, int year, int hour, int minute){
this.day = day;
this.sec = sec;
this.month = month;
this.year = year;
this.hour = hour;
this.minute = minute;
}
public int getHour() {
return hour;
}
public void setHour(int hour) {
this.hour = hour;
}
public int getMinute() {
return minute;
}
public void setMinute(int minute) {
this.minute = minute;
}
/**
*Get the day of this date as an int
*/
public int getDay(){
return day;
}
/**
*Get the month of this date as an int
*/
public int getMonth(){
return month;
}
/**
*Get the year of this date as an int
*/
public int getYear(){
return year;
}
/**
*Get this date as a String in the format: d-m-y
*/
public String getDate(){
return day+"-"+month+"-"+year+": "+getDisplayValue(hour)+":"+getDisplayValue(minute);
}
public String toString (){
return getDate();
}
private String getDisplayValue(int value)
{
if(value < 10) {
return "0" + value;
}
else {
return "" + value;
}
}
public boolean equals(Object o){
if (o instanceof Time){
Time other = (Time)o;
if (day == other.getDay() && month == other.getMonth() && year == other.getYear() &&
hour == other.getHour() && minute == other.getMinute()){
return true;
}
}
return false;
}
}