-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClockPuzzle.java
More file actions
61 lines (49 loc) · 1.15 KB
/
ClockPuzzle.java
File metadata and controls
61 lines (49 loc) · 1.15 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
public class ClockPuzzle {
private int hours;
private int minutes;
private final double TOTALDEGREE=360.00;
public String getTime(){
StringBuilder sb = new StringBuilder();
sb.append(hours);
sb.append(":");
sb.append(minutes);
printTime(sb.toString());
return sb.toString();
}
private void printTime(String time){
System.out.println("time = " + time);
}
public int getHours() {
return hours;
}
public void setHours(int hours) {
this.hours = hours;
}
public int getMinutes() {
return minutes;
}
public void setMinutes(int minutes) {
this.minutes = minutes;
}
/**
* calculate the angle
* @return clock angle
*/
public double getClockAngle(){
//assumption time is in 12 hours format
double angle =0.0;
if(hours<= 12 && hours >=0){
//hours are valid
if(minutes<=59 && minutes>=0){
//minutes are valid
double minDegree = minutes * (TOTALDEGREE/60);
double hourDegree = ( hours * (TOTALDEGREE/12) )+ (minutes * 0.5); //30/60 =0.5
angle = 360 - Math.abs(hourDegree - minDegree);
}
} else{
System.out.println(" Time is not correct");
angle = -1;
}
return angle;
}
}