4
4
5
5
public class Clock {
6
6
protected String type ;
7
- protected String brand ;
8
- protected Integer cost ;
9
- protected Integer hours , minutes ;
7
+ private String brand ;
8
+ private int cost ;
9
+ protected int hours , minutes ;
10
10
11
- public Clock (String brand , Integer cost , Integer hours , Integer minutes ) throws Exception {
11
+ public Clock (String brand , int cost , int hours , int minutes ) throws Exception {
12
12
this .type = "Common" ;
13
13
this .brand = brand ;
14
14
this .cost = cost ;
@@ -17,7 +17,7 @@ public Clock(String brand, Integer cost, Integer hours, Integer minutes) throws
17
17
setMinutes (minutes );
18
18
}
19
19
20
- protected void checkValue (Integer value ) throws Exception {
20
+ protected void checkValue (int value ) throws Exception {
21
21
if (value < 0 )
22
22
throw new Exception ("Value must be not negative!" );
23
23
}
@@ -26,11 +26,12 @@ public void setBrand(String brand) {
26
26
this .brand = brand ;
27
27
}
28
28
29
- public void setCost (Integer cost ) {
29
+ public void setCost (int cost ) throws Exception {
30
+ checkValue (cost );
30
31
this .cost = cost ;
31
32
}
32
33
33
- public void setHours (Integer hours ) throws Exception {
34
+ public void setHours (int hours ) throws Exception {
34
35
try {
35
36
checkValue (hours );
36
37
this .hours = hours % 24 ;
@@ -39,7 +40,7 @@ public void setHours(Integer hours) throws Exception {
39
40
}
40
41
}
41
42
42
- public void setMinutes (Integer minutes ) throws Exception {
43
+ public void setMinutes (int minutes ) throws Exception {
43
44
try {
44
45
checkValue (minutes );
45
46
setHours (this .hours + minutes / 60 );
@@ -49,23 +50,23 @@ public void setMinutes(Integer minutes) throws Exception {
49
50
}
50
51
}
51
52
52
- public Integer getHours () {
53
+ public int getHours () {
53
54
return this .hours ;
54
55
}
55
56
56
- public Integer getMinutes () {
57
+ public int getMinutes () {
57
58
return this .minutes ;
58
59
}
59
60
60
61
public String getBrand () {
61
62
return this .brand ;
62
63
}
63
64
64
- public Integer getCost () {
65
+ public int getCost () {
65
66
return this .cost ;
66
67
}
67
68
68
- public void increaseTime (Integer value ) throws Exception {
69
+ public void increaseTime (int value ) throws Exception {
69
70
try {
70
71
checkValue (value );
71
72
setMinutes ((this .minutes + value ));
@@ -85,16 +86,16 @@ public void printTime() {
85
86
86
87
87
88
public static class AdvancedClock extends Clock {
88
- private Integer seconds ;
89
+ private int seconds ;
89
90
90
- public AdvancedClock (String brand , Integer cost , Integer hours , Integer minutes , Integer seconds ) throws Exception {
91
+ public AdvancedClock (String brand , int cost , int hours , int minutes , int seconds ) throws Exception {
91
92
super (brand , cost , hours , minutes );
92
93
93
94
this .type = "Advanced" ;
94
95
setSeconds (seconds );
95
96
}
96
97
97
- public void setSeconds (Integer seconds ) throws Exception {
98
+ public void setSeconds (int seconds ) throws Exception {
98
99
try {
99
100
checkValue (seconds );
100
101
setMinutes (this .minutes + seconds / 60 );
@@ -104,12 +105,12 @@ public void setSeconds(Integer seconds) throws Exception {
104
105
}
105
106
}
106
107
107
- public Integer getSeconds () {
108
+ public int getSeconds () {
108
109
return this .seconds ;
109
110
}
110
111
111
112
@ Override
112
- public void increaseTime (Integer value ) throws Exception {
113
+ public void increaseTime (int value ) throws Exception {
113
114
try {
114
115
checkValue (value );
115
116
setSeconds ((this .seconds + value ));
0 commit comments