質問編集履歴

1

わからなくて教えてほしい部分にコメントアウトしました。おねがいいたいします。

2019/06/08 20:00

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -12,11 +12,9 @@
12
12
 
13
13
  ```java
14
14
 
15
- ソースコード
15
+ import java.util.Random;
16
16
 
17
- ```import java.util.Random;
18
-
19
- public class RandomTimer extends Thread{
17
+ class RandomTimer extends Thread{
20
18
 
21
19
  long count;
22
20
 
@@ -24,31 +22,19 @@
24
22
 
25
23
 
26
24
 
27
- public RandomTimer() {
25
+ public RandomTimer(long count,boolean runnnig) {
28
26
 
27
+ //最大待ち時間(ミリ秒)を受け取るコンストラクタを作りたい
28
+
29
+          Random rand = new Random();//0から最大待ち時間までの間のランダムな値をRandomクラスで生成
30
+
29
- setCount(count);
31
+ long time = rand.nextInt(10);
32
+
33
+ count = ;/生成した値を初期値として代入;
30
34
 
31
35
  }
32
36
 
33
- public long getCount() {
34
-
35
- return count;
36
-
37
- }
38
-
39
- int MaxTime = 5;
40
-
41
- Random rand = new Random();
42
-
43
- int time = rand.nextInt(5);
44
-
45
- public void setCount(long count) {
46
-
47
- this.count = time;
48
-
49
- }
50
-
51
- public void run() {
37
+ public void run(){
52
38
 
53
39
  while(running) {
54
40
 
@@ -62,13 +48,11 @@
62
48
 
63
49
  }
64
50
 
65
- for(long count = 11 ;count < 0;count--) {
51
+ count = count - 10;
66
52
 
67
- if(count < 0) {
53
+ if(count < 0) {
68
54
 
69
- System.out.println("*");
55
+ System.out.println("*");
70
-
71
- }
72
56
 
73
57
  }
74
58
 
@@ -76,49 +60,49 @@
76
60
 
77
61
  }
78
62
 
79
- public long responseTime() {
63
+ public long reponseTime() {
80
64
 
81
65
  return -count;
82
66
 
83
67
  }
84
68
 
85
- public void stopRunning() {
69
+ public void stopRunnig() {
86
70
 
87
- running = false;
71
+ running = false;
88
72
 
89
73
  }
90
74
 
91
75
  }
92
76
 
93
- class Quickpress{
77
+ class QuickPress{
94
-
95
-
96
78
 
97
79
  public static void main(String[] args) {
98
80
 
99
- RandomTimer t = new RandomTimer();
81
+ RandomTimer t = new RandomTimer(10, true);
100
82
 
101
- System.out.println("Hit enter to start:");
83
+ System.out.println("Hit enter to start:");
102
84
 
103
- t.start();
85
+ //Enterが押されたらRandomTimerインスタンスのスレッド実行を開始し、すぐにまたEnterキーを待つ
104
86
 
105
- System.out.println("タイム");
87
+ t.start();
106
88
 
107
- try {
89
+ System.out.println("タイム:"//二回目のEnterボタンが押されたらresponseTimeメソッドを読んで値を表示);
108
90
 
109
- t.join();
91
+ try {
110
92
 
111
- }catch(InterruptedException e) {
93
+ t.join();
112
94
 
113
- System.out.println(e);
95
+ }catch(InterruptedException e) {
114
96
 
97
+ System.out.println(e);
98
+
115
- }
99
+ }
116
100
 
117
101
  }
118
102
 
119
103
  }
120
104
 
121
-
105
+ ```
122
106
 
123
107
  ### 試したこと
124
108
 
@@ -138,6 +122,8 @@
138
122
 
139
123
 
140
124
 
125
+ 教えてほしい部分をコメントアウトしました。わかる方がいれば、教えていただきたいです。
126
+
141
127
  ### 補足情報(FW/ツールのバージョンなど)
142
128
 
143
129