-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab_5_2.java
77 lines (51 loc) · 1.62 KB
/
Lab_5_2.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
import java.util.*;
class Time{
int hour;
int minute;
int second;
Time(int hour,int minutes,int second){
this.hour =hour;
this.minute = minutes;
this.second = second;
}
public void addtime(Time T1, Time T2){
T1.second += T2.second;
if(T1.second>=60){
T1.minute++;
T1.second += -60;
}
T1.minute += T2.minute;
if(T1.minute>=60){
T1.hour++;
T1.minute += -60;
}
T1.hour += T2.hour;
printTime(T1);
}
public void printTime(Time T1){
System.out.print(T1.hour+" "+T1.minute+" "+second);
}
}
public class Lab_5_2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int hour;
int minute;
int second;
System.out.println("Enter the First Hours :");
hour = sc.nextInt();
System.out.println("Enter the First Minutes :");
minute = sc.nextInt();
System.out.println("Enter the First Second :");
second = sc.nextInt();
Time T1 = new Time(hour, minute, second);
System.out.println("Enter the Second Hours :");
hour= sc.nextInt();
System.out.println("Enter the Second Minutes :");
minute = sc.nextInt();
System.out.println("Enter the Second Seconds :");
second = sc.nextInt();
Time T2 = new Time(hour, minute, second);
T1.addtime(T1, T2);
}
}