-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBerkeley.java
More file actions
90 lines (73 loc) · 2.79 KB
/
Berkeley.java
File metadata and controls
90 lines (73 loc) · 2.79 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
import java.util.*;
import java.io.*;
public class Berkeley {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int s_Hours, s_Minutes, c1_Hours, c1_Minutes, c2_Hours, c2_Minutes;
int s_Time, c1_Time, c2_Time;
System.out.println("Time Synchronization");
System.out.println("Server Time:");
System.out.println("Enter hour:");
s_Hours = sc.nextInt();
System.out.println("Enter minutes:");
s_Minutes = sc.nextInt();
s_Time = s_Hours * 60 + s_Minutes;
System.out.println("Client1 Time:");
System.out.println("Enter hour:");
c1_Hours = sc.nextInt();
System.out.println("Enter minutes:");
c1_Minutes = sc.nextInt();
c1_Time = c1_Hours * 60 + c1_Minutes;
System.out.println("Cleint2 Time:");
System.out.println("Enter hour:");
c2_Hours = sc.nextInt();
System.out.println("Enter minutes:");
c2_Minutes = sc.nextInt();
c2_Time = c2_Hours * 60 + c2_Minutes;
int time_Average = (s_Time + c1_Time + c2_Time) / 3;
int difference;
difference = time_Average - s_Time;
if (difference == 0) {
System.out.println("Server time is perfect");
} else if (difference < 0) {
System.out.println("Server has to backward clock by " + (-difference) + " mins");
} else {
System.out.println("Server has to forward clock by " + difference + " mins");
}
difference = time_Average - c1_Time;
if (difference == 0) {
System.out.println("Cleint1 time is perfect");
} else if (difference < 0) {
System.out.println("Cleint1 has to backward clock by " + (-difference) + " mins");
} else {
System.out.println("Cleint1 has to forward clock by " + difference + " mins");
}
difference = time_Average - c2_Time;
if (difference == 0) {
System.out.println("Cleint2 time is perfect");
} else if (difference < 0) {
System.out.println("Cleint2 has to backward clock by " + (-difference) + " mins");
} else {
System.out.println("Cleint2 has to forward clock by " + difference + " mins");
}
System.out.println("New Time After Synchronizaion is " + (time_Average/60) + " hours and "+ (time_Average%60));
}
}
/* OUTPUT
Time Synchronization
Server Time:
Enter hour:
5 20
Enter minutes:
Client1 Time:
Enter hour:
5 30 5 40
Enter minutes:
Cleint2 Time:
Enter hour:
Enter minutes:
Server has to forward clock by 10 mins
Cleint1 time is perfect
Cleint2 has to backward clock by 10 mins
New Time After Synchronizaion is 5 hours and 30
*/