質問編集履歴

3

誤字を修正しました

2015/12/21 16:08

投稿

mnmtksk
mnmtksk

スコア13

test CHANGED
File without changes
test CHANGED
@@ -186,6 +186,6 @@
186
186
 
187
187
  ```
188
188
 
189
- このコードでは、inputがexistingStringと全く同じでなければ、警告メッセージがプリントされました。
189
+ このコードでは、inputColournameColourと全く同じでなければ、警告メッセージがプリントされました。
190
190
 
191
191
  アドバイスをお願いします。

2

コードを加筆、コメントを編集しました。

2015/12/21 16:08

投稿

mnmtksk
mnmtksk

スコア13

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- Javaでプルなゲームを作成しているプログラミング初心者です。
1
+ Javaでマスターマイを作成しているプログラミング初心者です。
2
2
 
3
3
 
4
4
 
@@ -22,25 +22,165 @@
22
22
 
23
23
 
24
24
 
25
- 以下そのコードです。一部抜粋、省略していま
25
+ 以下そのコードです。作成段階なので完成していません
26
26
 
27
27
  ```Java
28
28
 
29
- int counter=0;
29
+ public static void main(String[] args){
30
30
 
31
- while(counter<numberOfTrial){
31
+ Scanner scan = new Scanner(System.in);
32
32
 
33
- String input = scan.next();
33
+
34
34
 
35
- if(input.contains(existingString[counter])){
35
+ boolean condition = true;
36
36
 
37
- newString[counter]=input;
37
+ int numberPeg = 0;
38
38
 
39
+ String [] orderPeg = null;
40
+
41
+ int numberColour = 0;
42
+
43
+ String[] nameColour=null;
44
+
45
+
46
+
47
+ System.out.println("Enter the number of pegs.");
48
+
49
+ try{
50
+
51
+ while(condition){
52
+
53
+ numberPeg = scan.nextInt();
54
+
55
+ if(numberPeg<9){
56
+
57
+ orderPeg = new String [numberPeg];
58
+
39
- counter++;
59
+ condition=false;
60
+
61
+ }
62
+
63
+ else{System.err.println("Enter the number between 3-8.");}
64
+
65
+ }
40
66
 
41
67
  }
42
68
 
69
+ catch(InputMismatchException ime){System.err.println("Input valid argument.");}
70
+
71
+ condition=true;
72
+
73
+
74
+
75
+ System.out.println("Enter the number of colours.");
76
+
77
+ try{
78
+
79
+ while(condition){
80
+
43
- else{System.err.println();}
81
+ numberColour = scan.nextInt();
82
+
83
+ if(numberColour<=numberPeg){
84
+
85
+ nameColour = new String [numberColour];
86
+
87
+ condition=false;
88
+
89
+ }
90
+
91
+ else{
92
+
93
+ System.err.println("Enter appropriate number.");
94
+
95
+ }
96
+
97
+ }
98
+
99
+ }
100
+
101
+ catch(InputMismatchException ime){System.err.println("Input valid argument.");}
102
+
103
+ condition=true;
104
+
105
+
106
+
107
+ System.out.println("Enter colours.");
108
+
109
+ try{
110
+
111
+ try{
112
+
113
+ int counter=0;
114
+
115
+ while(counter<nameColour.length){
116
+
117
+ String inputColour = scan.next();
118
+
119
+ if(inputColour.equals("blue")||inputColour.equals("green")||inputColour.equals("orange")||inputColour.equals("purple")){
120
+
121
+ nameColour[counter]=inputColour;
122
+
123
+ counter++;
124
+
125
+ }
126
+
127
+ else{System.err.println("Colours must be blue, green, orange or purple.");}
128
+
129
+ }
130
+
131
+ }
132
+
133
+ catch(NullPointerException npe){}
134
+
135
+ }
136
+
137
+ catch(InputMismatchException ime){System.err.println("Input valid argument.");}
138
+
139
+
140
+
141
+ //ここが問題の箇所です
142
+
143
+ System.out.println("Enter the colour of the order.");
144
+
145
+ try{
146
+
147
+ try{
148
+
149
+ int counter=0;
150
+
151
+ while(counter<numberPeg){
152
+
153
+ String inputColour = scan.next();
154
+
155
+ //ここで比較する際に、nameColourの0番目の要素だけでなく、全ての要素と比較して、inputColourがnameColourに含まれているのか確かめたいです。
156
+
157
+ if(inputColour.contains(nameColour[counter])){
158
+
159
+ orderPeg[counter]=inputColour;
160
+
161
+ counter++;
162
+
163
+ }
164
+
165
+ else{System.err.println("Must be the same colour you chose before.");}
166
+
167
+ }
168
+
169
+ }
170
+
171
+ catch(NullPointerException npe){}
172
+
173
+ }
174
+
175
+ catch(InputMismatchException ime){System.err.println("Input valid argument.");}
176
+
177
+
178
+
179
+ System.out.println("GAME START");
180
+
181
+ System.out.println("The number of pegs are "+numberPeg);
182
+
183
+
44
184
 
45
185
  }
46
186
 

1

初心者マークを付加しました

2015/12/21 16:06

投稿

mnmtksk
mnmtksk

スコア13

test CHANGED
File without changes
test CHANGED
File without changes