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

質問編集履歴

1

ご指摘いただいた点を修正しつつ新たに生まれたエラーを書き加えました!

2020/02/26 09:57

投稿

chimo
chimo

スコア55

title CHANGED
File without changes
body CHANGED
@@ -15,6 +15,8 @@
15
15
 
16
16
  上記をふまえて私が作成したコードは以下の通りです。
17
17
  ```Jave
18
+ import java.util.Random;
19
+
18
20
  class Ex2_02_1_Player {
19
21
 
20
22
  //---フィールド----------------------------------------------
@@ -24,7 +26,7 @@
24
26
 
25
27
  //---コンストラクタ------------------------------------------------
26
28
 
27
- class Ex2_02_1_Player(String nm){
29
+ Ex2_02_1_Player(String nm){
28
30
  name = nm ;
29
31
  }
30
32
 
@@ -33,13 +35,13 @@
33
35
  //makeHandStatusメソッド
34
36
  void makeHandStatus(){
35
37
 
36
- Stirng[] hands = {"グー", "チョキ", "パー"} ;
38
+ Stirng[] hands = { "グー", "チョキ", "パー" } ;
37
39
 
38
40
  Random r = new Random() ;
39
- handStatus = hands[r.nextInt(3)]
41
+ handStatus = hands[r.nextInt(3)] ;
40
42
 
41
43
  }
42
- }
44
+ }
43
45
  ```
44
46
 
45
47
  ●ジャンケンクラス
@@ -62,12 +64,12 @@
62
64
  public static void main (String[] args) {
63
65
 
64
66
  //シナリオ①:コマンドライン引数から2名のプレイヤーの名前を受け取る。
65
- String player1 = args[0] ;
67
+ String player_1 = args[0] ;
66
- String player2 = args[1] ;
68
+ String player_2 = args[1] ;
67
-
69
+
68
70
  //シナリオ②:2名のプレイヤーを場に登場させる。
69
- Ex2_02_1_Player player1 = new Ex2_02_1_Player("args[0]") ;
71
+ Ex2_02_1_Player player1 = new Ex2_02_1_Player( player_1 ) ;
70
- Ex2_02_1_Player player2 = new Ex2_02_1_Player("args[1]") ;
72
+ Ex2_02_1_Player player2 = new Ex2_02_1_Player( player_2 ) ;
71
73
 
72
74
  //シナリオ③:それぞれのプレイヤーにジャンケンの手をださせる。
73
75
  System.out.println("じゃんけん…ぽん!!!!!") ;
@@ -75,8 +77,8 @@
75
77
  player1.makeHandStatus() ;
76
78
  player2.makeHandStatus() ;
77
79
 
78
- System.out.println("モコさんの手:" + player1.handStatus) ;
80
+ System.out.println( player1.name + "さんの手:" + player1.handStatus) ;
79
- System.out.println("ポチさんの手:" + player2.handStatus) ;
81
+ System.out.println( player2.name + "さんの手:" + player2.handStatus) ;
80
82
 
81
83
  //シナリオ④:勝敗の結果を表示する。
82
84
  System.out.println("結果は…") ;
@@ -87,15 +89,15 @@
87
89
 
88
90
  }else if(((player1.handStatus=="グー")&&(player2.handStatus=="チョキ"))||((player1.handStatus=="パー")&&(player2.handStatus=="グー"))||((player1.handStatus=="チョキ")&&(player2.handStatus=="パー"))){
89
91
 
90
- System.out.println("モコさんの勝利!!");
92
+ System.out.println( player1.name + "さんの勝利!!" );
91
93
 
92
94
  }else if(((player2.handStatus=="グー")&&(player1.handStatus=="チョキ"))||((player2.handStatus=="パー")&&(player1.handStatus=="グー"))||((player2.handStatus=="チョキ")&&(player1.handStatus=="パー"))){
93
95
 
94
- System.out.println("ポチさんの勝利!!");
96
+ System.out.println( player2.name + "さんの勝利!!" );
95
97
 
96
98
  }
97
-
99
+ }
98
-
100
+ }
99
101
  ```
100
102
 
101
103
  メインメソッドが含まれるクラスの方をコンパイルすると以下のようなエラーが出てきます。
@@ -111,4 +113,16 @@
111
113
 
112
114
  エラーがしてきしてくるところ以外で自分があやしいとおもうのは、ジャンケンを判定する時のif文の書き方がおかしいのか、プレーヤークラスがおかしいのかかなぁ…と思っていますが、本当に間違ているとことはどの部分で、どうすればコンパイルされるのでしょうか...。
113
115
 
114
- ご教授お願いいたします。
116
+ ご教授お願いいたします。
117
+
118
+ 【新たなエラー内容】
119
+ 先のエラーは解決しましたが、再度メインクラスの方をコンパイルしようとすると以下のようなエラーが表示されます。
120
+ Ex_2_02_1_Player.java:21: error: cannot find symbol
121
+ String[] hands = { "グー", "チョキ", "パー" }
122
+ symbol: class String
123
+ location: class Ex2_02_1_Player
124
+ 1 error
125
+
126
+ 配列を作りたいだけなんですけど、配列の作り方を復習しましたが見た目合ってる気しかしませんでした。何が間違っているのでしょうか...。
127
+
128
+ ご教授お願いします!!!