質問編集履歴

2

2016/05/31 07:56

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- 秒数が足して60になったら,1分足して正しい秒数を表示したいです.
1
+ Vcggbbvcvvhbbvvvbjbvgyyybvvg
test CHANGED
@@ -1,215 +1 @@
1
- ###前提・実現したいこと
2
-
3
- 60秒を超えたら分に1足して,正しい秒数を表示するようにしたい.
4
-
5
- ###発生している問題・エラーメッセージ
6
-
7
- 60秒を超え秒数が振り切ってしまう.
8
-
9
- ###該当のソースコード
10
-
11
-
12
-
13
- public class Time {
14
-
15
-
16
-
17
- private int hour, minute, second;
18
-
19
-
20
-
21
- public Time(int hour, int min, int sec) {
22
-
23
- this.hour = hour;
24
-
25
- this.minute = min;
26
-
27
- this.second = sec;
28
-
29
- }
30
-
31
-
32
-
33
- public Time() {
34
-
35
- this.hour = 0;
36
-
37
- this.minute = 0;
38
-
39
- this.second = 0;
40
-
41
- }
42
-
43
-
44
-
45
- public Time(int seconds) {
46
-
47
- this.hour = seconds / 3600;
48
-
49
- this.minute = (seconds / 3600 * this.hour) / 60;
50
-
51
- this.second = seconds - 3600 * this.hour - 60 * this.minute;
52
-
53
- }
54
-
55
-
56
-
57
- public void setHour(int hour) {
1
+ Buddha vjncccdffffccvvjjgccjohvvfgg
58
-
59
- this.hour = hour;
60
-
61
- }
62
-
63
-
64
-
65
- public int getHour() {
66
-
67
- return this.hour;
68
-
69
- }
70
-
71
-
72
-
73
- public void setMinute(int min) {
74
-
75
- if (min < 0 || min > 59) {
76
-
77
- throw new IllegalArgumentException("不適切な時間の入力がありました.処理を中断します.");
78
-
79
- } else {
80
-
81
- this.minute = min;
82
-
83
- }
84
-
85
- }
86
-
87
-
88
-
89
- public int getMinute() {
90
-
91
- return this.minute;
92
-
93
- }
94
-
95
-
96
-
97
- public void setSecond(int sec) {
98
-
99
- if (sec < 0 || sec > 59) {
100
-
101
- throw new IllegalArgumentException("不適切な時間の入力がありました.処理を中断します.");
102
-
103
- } else {
104
-
105
- this.second = sec;
106
-
107
- }
108
-
109
- }
110
-
111
-
112
-
113
- public int getSecond() {
114
-
115
- return this.second;
116
-
117
- }
118
-
119
-
120
-
121
- public String toString() {
122
-
123
- return this.hour + "時間" + this.minute + "分" + this.second + "秒";
124
-
125
- }
126
-
127
-
128
-
129
- public void add(Time time) {
130
-
131
- this.hour += time.hour;
132
-
133
- this.minute += time.minute;
134
-
135
- this.second += time.second;
136
-
137
- }
138
-
139
-
140
-
141
- public int diffInSeconds(Time time1, Time time2) {
142
-
143
- int s1 = time1.hour * 3600 + time1.minute * 60 + time1.second;
144
-
145
- int s2 = time2.hour * 3600 + time2.minute * 60 + time2.second;
146
-
147
- return s1 - s2;
148
-
149
- }
150
-
151
- }
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
- public class Main {
160
-
161
-
162
-
163
- public static void main(String[] args) {
164
-
165
- Time t1 = new Time(2, 18, 47);
166
-
167
- System.out.println(t1.getHour()+":"+t1.getMinute()+":"+t1.getSecond());
168
-
169
- Time t2 = new Time();
170
-
171
- t2.setHour(1);
172
-
173
- t2.setMinute(32);
174
-
175
- t2.setSecond(16);
176
-
177
- System.out.println(t2.toString());
178
-
179
- t1.add(t2);
180
-
181
- System.out.println(t1.toString());
182
-
183
- int s = t1.diffInSeconds(t1, t2);
184
-
185
- System.out.println(s+"秒間");
186
-
187
- Time t3 = new Time(s);
188
-
189
- System.out.println(t3);
190
-
191
- }
192
-
193
- }
194
-
195
-
196
-
197
-
198
-
199
- ###補足情報(言語/FW/ツール等のバージョンなど)
200
-
201
- NetBeans8.1
202
-
203
- ###出力結果
204
-
205
-
206
-
207
- 2:18:47
208
-
209
- 1時間32分16秒
210
-
211
- 3時間50分63秒
212
-
213
- 8327秒間
214
-
215
- 2時間0分1127秒

1

タグの変更

2016/05/31 07:56

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
File without changes