-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClock.java
More file actions
98 lines (82 loc) · 1.65 KB
/
Copy pathClock.java
File metadata and controls
98 lines (82 loc) · 1.65 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
import java.awt.desktop.SystemSleepEvent;
public class Clock {
private int h;
private int min;
public int getMin() {
return min;
}
public int getH() {
return h;
}
public Clock(int hour, int min){
this.min= min;
this.h= hour;
while (true){
if (this.h>23){
this.h=this.h-24;
}
else{
break;
}
}
}
public Clock(int min){
while(true) {
if (min>59) {
this.h=this.h+1;
min=min-60;
}
else{
this.min=min;
}
if(this.min==min){
break;
}
}
}
public Clock(String a){
String [] x=a.split(":");
int hour= Integer.parseInt(x[0]);
int minute= Integer.parseInt(x[1]);
this.h= hour;
this.min= minute;
}
public Clock add(int min) {
Clock erg= new Clock(0,min);
erg.h= this.h;
erg.min= erg.min+this.min;
while(true) {
if (erg.min > 59) {
erg.h = erg.h + 1;
erg.min = erg.min - 60;
} else {
break;
}
}
return erg;
}
public Clock add(Clock c) {
Clock erg= new Clock(0, 0);
erg.h=this.h+c.h;
if(erg.h>23){
erg.h=erg.h-24;
}
erg.min=this.min+c.min;
if (erg.min>=60){
erg.h=erg.h+1;
erg.min=erg.min-60;
}
return erg;
}
public String toString() {
String min= ""+this.min;
String h= ""+this.h;
String ausg=h+":"+min;
return ausg;
}
public static void main(String[] args) {
Clock a= new Clock( 0, 46);
a=a.add(30);
System.out.println(a.toString());
}
}