-
Notifications
You must be signed in to change notification settings - Fork 0
/
ass1_3.java
72 lines (62 loc) · 1.21 KB
/
ass1_3.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
import java.util.Scanner;
class Time
{
int hour,min,sec;
Time(int d_hour,int d_min,int d_sec)
{
hour=d_hour;
min=d_min;
sec=d_sec;
}
Time()
{
hour=0;
min=0;
sec=0;
}
void sum(Time t1,Time t2)
{
int temp;
sec=t1.sec+t2.sec;
temp=sec/60;
sec%=60;
min=t1.min+t2.min+temp;
temp=min/60;
min%=60;
hour=t1.hour=t2.hour+temp;
System.out.println("Sum of time of object 1 and object 2 is: ");
}
void showTime()
{
System.out.println("Time is: "+hour+" : "+min+" : "+sec);
}
}
class ass1_3
{
public static void main(String s[])
{
int hour,min,sec;
Scanner sc=new Scanner(System.in);
System.out.println("Enter Time for object 1: ");
System.out.print("Enter Hour: ");
hour=sc.nextInt();
System.out.print("Enter Min: ");
min=sc.nextInt();
System.out.print("Enter Sec: ");
sec=sc.nextInt();
Time t1=new Time(hour,min,sec);
t1.showTime();
System.out.println("Enter Time for object 2: ");
System.out.print("Enter Hour: ");
hour=sc.nextInt();
System.out.print("Enter Min: ");
min=sc.nextInt();
System.out.print("Enter Sec: ");
sec=sc.nextInt();
Time t2=new Time(hour,min,sec);
t2.showTime();
Time t3=new Time();
t3.sum(t1,t2);
t3.showTime();
}
}