質問するログイン新規登録

質問編集履歴

2

2016/05/31 07:56

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- 秒数が足して60になったら,1分足して正しい秒数を表示したいです.
1
+ Vcggbbvcvvhbbvvvbjbvgyyybvvg
body CHANGED
@@ -1,108 +1,1 @@
1
- ###前提・実現したいこと
2
- 60秒を超えたら分に1足して,正しい秒数を表示するようにしたい.
3
- ###発生している問題・エラーメッセージ
4
- 60秒を超え秒数が振り切ってしまう.
5
- ###該当のソースコード
6
-
7
- public class Time {
8
-
9
- private int hour, minute, second;
10
-
11
- public Time(int hour, int min, int sec) {
12
- this.hour = hour;
13
- this.minute = min;
14
- this.second = sec;
15
- }
16
-
17
- public Time() {
18
- this.hour = 0;
19
- this.minute = 0;
20
- this.second = 0;
21
- }
22
-
23
- public Time(int seconds) {
24
- this.hour = seconds / 3600;
25
- this.minute = (seconds / 3600 * this.hour) / 60;
26
- this.second = seconds - 3600 * this.hour - 60 * this.minute;
27
- }
28
-
29
- public void setHour(int hour) {
1
+ Buddha vjncccdffffccvvjjgccjohvvfgg
30
- this.hour = hour;
31
- }
32
-
33
- public int getHour() {
34
- return this.hour;
35
- }
36
-
37
- public void setMinute(int min) {
38
- if (min < 0 || min > 59) {
39
- throw new IllegalArgumentException("不適切な時間の入力がありました.処理を中断します.");
40
- } else {
41
- this.minute = min;
42
- }
43
- }
44
-
45
- public int getMinute() {
46
- return this.minute;
47
- }
48
-
49
- public void setSecond(int sec) {
50
- if (sec < 0 || sec > 59) {
51
- throw new IllegalArgumentException("不適切な時間の入力がありました.処理を中断します.");
52
- } else {
53
- this.second = sec;
54
- }
55
- }
56
-
57
- public int getSecond() {
58
- return this.second;
59
- }
60
-
61
- public String toString() {
62
- return this.hour + "時間" + this.minute + "分" + this.second + "秒";
63
- }
64
-
65
- public void add(Time time) {
66
- this.hour += time.hour;
67
- this.minute += time.minute;
68
- this.second += time.second;
69
- }
70
-
71
- public int diffInSeconds(Time time1, Time time2) {
72
- int s1 = time1.hour * 3600 + time1.minute * 60 + time1.second;
73
- int s2 = time2.hour * 3600 + time2.minute * 60 + time2.second;
74
- return s1 - s2;
75
- }
76
- }
77
-
78
-
79
-
80
- public class Main {
81
-
82
- public static void main(String[] args) {
83
- Time t1 = new Time(2, 18, 47);
84
- System.out.println(t1.getHour()+":"+t1.getMinute()+":"+t1.getSecond());
85
- Time t2 = new Time();
86
- t2.setHour(1);
87
- t2.setMinute(32);
88
- t2.setSecond(16);
89
- System.out.println(t2.toString());
90
- t1.add(t2);
91
- System.out.println(t1.toString());
92
- int s = t1.diffInSeconds(t1, t2);
93
- System.out.println(s+"秒間");
94
- Time t3 = new Time(s);
95
- System.out.println(t3);
96
- }
97
- }
98
-
99
-
100
- ###補足情報(言語/FW/ツール等のバージョンなど)
101
- NetBeans8.1
102
- ###出力結果
103
-
104
- 2:18:47
105
- 1時間32分16秒
106
- 3時間50分63秒
107
- 8327秒間
108
- 2時間0分1127秒

1

タグの変更

2016/05/31 07:56

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
File without changes