-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimepiece.java
95 lines (91 loc) · 2.49 KB
/
Timepiece.java
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
import java.util.Scanner;
public class Contador{
private int h,m;
private int type;
public Contador(int type) {
this.type=type;
resetTimer();
}
public void ticTac() {
if(this.type==24){
this.m++;
if(this.m==60 && this.h<24){
this.h++;
this.m=0;
}
}else{
this.m++;
if(this.m==60){
this.h++;
this.m=0;
}
if(this.h==12 && this.m==0){
this.h=-1;
}
if(this.h==13 && this.m == 0){
this.h=1;
}
}
}
public void resetTimer(){
if(this.type==12){
this.h=12;
}else{
this.h=0;
}
this.m=0;
}
public int getHour () {
return h;
}
public int getMin () {
return m;
}
}
public class Relogio{
private int type;
Contador timing;
public Relogio (int type){
timing = new Contador(type);
this.type=type;
}
public void showTimes(){
if(this.type==24){
do{
if(timing.getMin()<10){
System.out.println(">"+ timing.getHour() +":0"+ timing.getMin()+" hours");
}else{
System.out.println(">"+ timing.getHour() +":"+ timing.getMin()+" hours");
}
timing.ticTac();
}while(timing.getHour()<24);
}else{
while(timing.getHour()!=-1){
if(timing.getMin()<10){
System.out.println("> "+timing.getHour() +":0"+ timing.getMin()+" A.M.");
}else{
System.out.println("> "+timing.getHour() +":"+ timing.getMin()+" A.M.");
}
timing.ticTac();
}timing.resetTimer();
while(timing.getHour()!=-1){
if(timing.getMin()<10){
System.out.println("> "+timing.getHour() +":0"+ timing.getMin()+" P.M.");
}else{
System.out.println("> "+timing.getHour() +":"+ timing.getMin()+" P.M.");
}
timing.ticTac();
}
}
}
}
public class Main{
public static void main(String[] args) {
int type;
Scanner input = new Scanner(System.in);
System.out.println("What is the hour format ? (24||12)");
type=input.nextInt();
Relogio r = new Relogio(type);
r.showTimes();
}
}