質問編集履歴
1
ご指摘いただいた点を修正しつつ新たに生まれたエラーを書き加えました!
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,6 +32,10 @@
|
|
32
32
|
|
33
33
|
```Jave
|
34
34
|
|
35
|
+
import java.util.Random;
|
36
|
+
|
37
|
+
|
38
|
+
|
35
39
|
class Ex2_02_1_Player {
|
36
40
|
|
37
41
|
|
@@ -50,7 +54,7 @@
|
|
50
54
|
|
51
55
|
|
52
56
|
|
53
|
-
|
57
|
+
Ex2_02_1_Player(String nm){
|
54
58
|
|
55
59
|
name = nm ;
|
56
60
|
|
@@ -68,136 +72,136 @@
|
|
68
72
|
|
69
73
|
|
70
74
|
|
71
|
-
Stirng[] hands = {"グー", "チョキ", "パー"} ;
|
75
|
+
Stirng[] hands = { "グー", "チョキ", "パー" } ;
|
72
76
|
|
73
77
|
|
74
78
|
|
75
79
|
Random r = new Random() ;
|
76
80
|
|
77
|
-
handStatus = hands[r.nextInt(3)]
|
81
|
+
handStatus = hands[r.nextInt(3)] ;
|
78
82
|
|
79
83
|
|
80
84
|
|
81
85
|
}
|
82
86
|
|
87
|
+
}
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
●ジャンケンクラス
|
94
|
+
|
95
|
+
・メソッド - mainメソッド
|
96
|
+
|
97
|
+
<シナリオ①>
|
98
|
+
|
99
|
+
コマンドライン引数より2つの文字列を受け取る。 (ジャンケンを行う2名のプレイヤーの名前として利用)
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
<シナリオ②>
|
104
|
+
|
105
|
+
2名のプレイヤーを場に登場させる。(インスタンス化する) インスタンス化の際はコマンドライン引数で受け取った文字列をそれぞれ コンストラクタに渡す。
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
<シナリオ③>
|
110
|
+
|
111
|
+
それぞれのプレイヤーに手を握らせる。 ※握らせる前に「じゃんけん・・・ぽん!!!!!」というメッセージを画面に表示。 ※それぞれのプレイヤーがどんな手を出したか、それぞれ 「 (nameの値) さんの手:( handStatus の値))」の形で画面に表示。
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
<シナリオ④>
|
116
|
+
|
117
|
+
勝敗の結果を画面に表示する。 ※はじめに「結果は・・・」というメッセージを画面に表示。 ※あいこだった場合は「あいこ!勝負つかず!」というメッセージを画面に表示。 ※あいこでない場合は「(nameの値)さんの勝利!」というメッセージを画面に表示。
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
上記をふまえて私が作成したコードは以下の通りです。
|
122
|
+
|
123
|
+
```Java
|
124
|
+
|
125
|
+
class Ex2_02_1_Janken {
|
126
|
+
|
127
|
+
public static void main (String[] args) {
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
//シナリオ①:コマンドライン引数から2名のプレイヤーの名前を受け取る。
|
132
|
+
|
133
|
+
String player_1 = args[0] ;
|
134
|
+
|
135
|
+
String player_2 = args[1] ;
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
//シナリオ②:2名のプレイヤーを場に登場させる。
|
140
|
+
|
141
|
+
Ex2_02_1_Player player1 = new Ex2_02_1_Player( player_1 ) ;
|
142
|
+
|
143
|
+
Ex2_02_1_Player player2 = new Ex2_02_1_Player( player_2 ) ;
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
//シナリオ③:それぞれのプレイヤーにジャンケンの手をださせる。
|
148
|
+
|
149
|
+
System.out.println("じゃんけん…ぽん!!!!!") ;
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
player1.makeHandStatus() ;
|
154
|
+
|
155
|
+
player2.makeHandStatus() ;
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
System.out.println( player1.name + "さんの手:" + player1.handStatus) ;
|
160
|
+
|
161
|
+
System.out.println( player2.name + "さんの手:" + player2.handStatus) ;
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
//シナリオ④:勝敗の結果を表示する。
|
166
|
+
|
167
|
+
System.out.println("結果は…") ;
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
if(player1.handStatus==player2.handStatus){
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
System.out.println("あいこ!勝負つかず!!");
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
}else if(((player1.handStatus=="グー")&&(player2.handStatus=="チョキ"))||((player1.handStatus=="パー")&&(player2.handStatus=="グー"))||((player1.handStatus=="チョキ")&&(player2.handStatus=="パー"))){
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
System.out.println( player1.name + "さんの勝利!!" );
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
}else if(((player2.handStatus=="グー")&&(player1.handStatus=="チョキ"))||((player2.handStatus=="パー")&&(player1.handStatus=="グー"))||((player2.handStatus=="チョキ")&&(player1.handStatus=="パー"))){
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
System.out.println( player2.name + "さんの勝利!!" );
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
}
|
198
|
+
|
83
199
|
}
|
84
200
|
|
85
201
|
```
|
86
202
|
|
87
203
|
|
88
204
|
|
89
|
-
●ジャンケンクラス
|
90
|
-
|
91
|
-
・メソッド - mainメソッド
|
92
|
-
|
93
|
-
<シナリオ①>
|
94
|
-
|
95
|
-
コマンドライン引数より2つの文字列を受け取る。 (ジャンケンを行う2名のプレイヤーの名前として利用)
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
<シナリオ②>
|
100
|
-
|
101
|
-
2名のプレイヤーを場に登場させる。(インスタンス化する) インスタンス化の際はコマンドライン引数で受け取った文字列をそれぞれ コンストラクタに渡す。
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
<シナリオ③>
|
106
|
-
|
107
|
-
それぞれのプレイヤーに手を握らせる。 ※握らせる前に「じゃんけん・・・ぽん!!!!!」というメッセージを画面に表示。 ※それぞれのプレイヤーがどんな手を出したか、それぞれ 「 (nameの値) さんの手:( handStatus の値))」の形で画面に表示。
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
<シナリオ④>
|
112
|
-
|
113
|
-
勝敗の結果を画面に表示する。 ※はじめに「結果は・・・」というメッセージを画面に表示。 ※あいこだった場合は「あいこ!勝負つかず!」というメッセージを画面に表示。 ※あいこでない場合は「(nameの値)さんの勝利!」というメッセージを画面に表示。
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
上記をふまえて私が作成したコードは以下の通りです。
|
118
|
-
|
119
|
-
```Java
|
120
|
-
|
121
|
-
class Ex2_02_1_Janken {
|
122
|
-
|
123
|
-
public static void main (String[] args) {
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
//シナリオ①:コマンドライン引数から2名のプレイヤーの名前を受け取る。
|
128
|
-
|
129
|
-
String player1 = args[0] ;
|
130
|
-
|
131
|
-
String player2 = args[1] ;
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
//シナリオ②:2名のプレイヤーを場に登場させる。
|
136
|
-
|
137
|
-
Ex2_02_1_Player player1 = new Ex2_02_1_Player("args[0]") ;
|
138
|
-
|
139
|
-
Ex2_02_1_Player player2 = new Ex2_02_1_Player("args[1]") ;
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
//シナリオ③:それぞれのプレイヤーにジャンケンの手をださせる。
|
144
|
-
|
145
|
-
System.out.println("じゃんけん…ぽん!!!!!") ;
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
player1.makeHandStatus() ;
|
150
|
-
|
151
|
-
player2.makeHandStatus() ;
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
System.out.println("モコさんの手:" + player1.handStatus) ;
|
156
|
-
|
157
|
-
System.out.println("ポチさんの手:" + player2.handStatus) ;
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
//シナリオ④:勝敗の結果を表示する。
|
162
|
-
|
163
|
-
System.out.println("結果は…") ;
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
if(player1.handStatus==player2.handStatus){
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
System.out.println("あいこ!勝負つかず!!");
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
}else if(((player1.handStatus=="グー")&&(player2.handStatus=="チョキ"))||((player1.handStatus=="パー")&&(player2.handStatus=="グー"))||((player1.handStatus=="チョキ")&&(player2.handStatus=="パー"))){
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
System.out.println("モコさんの勝利!!");
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
}else if(((player2.handStatus=="グー")&&(player1.handStatus=="チョキ"))||((player2.handStatus=="パー")&&(player1.handStatus=="グー"))||((player2.handStatus=="チョキ")&&(player1.handStatus=="パー"))){
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
System.out.println("ポチさんの勝利!!");
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
}
|
192
|
-
|
193
|
-
}
|
194
|
-
|
195
|
-
}
|
196
|
-
|
197
|
-
```
|
198
|
-
|
199
|
-
|
200
|
-
|
201
205
|
メインメソッドが含まれるクラスの方をコンパイルすると以下のようなエラーが出てきます。
|
202
206
|
|
203
207
|
|
@@ -225,3 +229,27 @@
|
|
225
229
|
|
226
230
|
|
227
231
|
ご教授お願いいたします。
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
【新たなエラー内容】
|
236
|
+
|
237
|
+
先のエラーは解決しましたが、再度メインクラスの方をコンパイルしようとすると以下のようなエラーが表示されます。
|
238
|
+
|
239
|
+
Ex_2_02_1_Player.java:21: error: cannot find symbol
|
240
|
+
|
241
|
+
String[] hands = { "グー", "チョキ", "パー" }
|
242
|
+
|
243
|
+
symbol: class String
|
244
|
+
|
245
|
+
location: class Ex2_02_1_Player
|
246
|
+
|
247
|
+
1 error
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
配列を作りたいだけなんですけど、配列の作り方を復習しましたが見た目合ってる気しかしませんでした。何が間違っているのでしょうか...。
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
ご教授お願いします!!!
|