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

質問編集履歴

1

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

2019/06/08 20:00

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -5,60 +5,52 @@
5
5
  ### 該当のソースコード
6
6
 
7
7
  ```java
8
- ソースコード
9
- ```import java.util.Random;
8
+ import java.util.Random;
10
- public class RandomTimer extends Thread{
9
+ class RandomTimer extends Thread{
11
10
  long count;
12
11
  boolean running = true;
13
12
 
14
- public RandomTimer() {
13
+ public RandomTimer(long count,boolean runnnig) {
14
+ //最大待ち時間(ミリ秒)を受け取るコンストラクタを作りたい
15
+          Random rand = new Random();//0から最大待ち時間までの間のランダムな値をRandomクラスで生成
15
- setCount(count);
16
+ long time = rand.nextInt(10);
17
+ count = ;/生成した値を初期値として代入;
16
18
  }
17
- public long getCount() {
18
- return count;
19
- }
20
- int MaxTime = 5;
21
- Random rand = new Random();
22
- int time = rand.nextInt(5);
23
- public void setCount(long count) {
24
- this.count = time;
25
- }
26
- public void run() {
19
+ public void run(){
27
20
  while(running) {
28
21
  try {
29
22
  Thread.sleep(10);
30
23
  }catch(InterruptedException e) {
31
24
  System.out.println(e);
32
25
  }
33
- for(long count = 11 ;count < 0;count--) {
26
+ count = count - 10;
34
- if(count < 0) {
27
+ if(count < 0) {
35
- System.out.println("*");
28
+ System.out.println("*");
36
- }
37
29
  }
38
30
  }
39
31
  }
40
- public long responseTime() {
32
+ public long reponseTime() {
41
33
  return -count;
42
34
  }
43
- public void stopRunning() {
35
+ public void stopRunnig() {
44
- running = false;
36
+ running = false;
45
37
  }
46
38
  }
47
- class Quickpress{
39
+ class QuickPress{
48
-
49
40
  public static void main(String[] args) {
50
- RandomTimer t = new RandomTimer();
41
+ RandomTimer t = new RandomTimer(10, true);
51
- System.out.println("Hit enter to start:");
42
+ System.out.println("Hit enter to start:");
43
+ //Enterが押されたらRandomTimerインスタンスのスレッド実行を開始し、すぐにまたEnterキーを待つ
52
- t.start();
44
+ t.start();
53
- System.out.println("タイム");
45
+ System.out.println("タイム:"//二回目のEnterボタンが押されたらresponseTimeメソッドを読んで値を表示);
54
- try {
46
+ try {
55
- t.join();
47
+ t.join();
56
- }catch(InterruptedException e) {
48
+ }catch(InterruptedException e) {
57
- System.out.println(e);
49
+ System.out.println(e);
50
+ }
58
51
  }
59
- }
60
52
  }
61
-
53
+ ```
62
54
  ### 試したこと
63
55
 
64
56
  Enterの処理の仕方などがいまいちよくわかりません.
@@ -68,6 +60,7 @@
68
60
  タイム:300
69
61
  というような実行結果にしたいです。
70
62
 
63
+ 教えてほしい部分をコメントアウトしました。わかる方がいれば、教えていただきたいです。
71
64
  ### 補足情報(FW/ツールのバージョンなど)
72
65
 
73
66
  ここにより詳細な情報を記載してください。