質問編集履歴

3

質問のグレードアップ

2016/05/14 03:38

投稿

gyro16
gyro16

スコア89

test CHANGED
@@ -1 +1 @@
1
- 3人のジャンケンの勝敗判定で詰まりました
1
+ 3人のジャンケンの勝敗判定で詰まりました。オブジェクト指向でジャンケンの手をクラスに変えるには?
test CHANGED
@@ -1,3 +1,17 @@
1
+ うーん、欲を言えば、オブジェクト指向でこなしたいです。
2
+
3
+ ヒントはもらっています。「ジャンケンの手をクラスにする」です。
4
+
5
+
6
+
7
+ オブジェクト指向でジャンケンの手のクラスにすると、どうなりますが、
8
+
9
+ extends 継承を使うにはどのように変えたらいいですか?
10
+
11
+ 今はジャンケンの手はフィールドですね。
12
+
13
+
14
+
1
15
  3人でのジャンケンの判定をしたいプログラムを作りたいのですが、詰まりました。
2
16
 
3
17
 
@@ -92,59 +106,49 @@
92
106
 
93
107
  if(maxType == 2){
94
108
 
95
- int a,b,c;
109
+ if(hands[0] == Player.STONE && hands[1] ==Player.STONE && hands[2] == Player.SCISSORS){
96
110
 
97
- for(int i = 0; i < hands.length; i++){
111
+ System.out.println(player1.getName() + "と" + player2.getName() + "が勝ちました!");
98
112
 
99
- for(int j = i + 1; j < hands.length; j++){
113
+ player1.winCount_++;
100
114
 
101
- if(hands[i] != hands[j]){
115
+ player2.winCount_++;
102
116
 
103
- a = i;
117
+ } else if(hands[0] == Player.STONE && hands[1] == Player.SCISSORS && hands[2] == Player.STONE){
104
118
 
105
- b = j;
119
+ System.out.println(player1.getName() + "と" + player3.getName() + "が勝ちました!");
106
120
 
107
- }
121
+ player1.winCount_++;
108
122
 
109
- }
123
+ player3.winCount_++;
124
+
125
+ } else if(hands[0] == Player.SCISSORS && hands[1] == Player.STONE && hands[2] == Player.STONE){
126
+
127
+ System.out.println(player2.getName() + "と" + player3.getName() + "が勝ちました!");
128
+
129
+ player2.winCount_++;
130
+
131
+ player3.winCount_++;
110
132
 
111
133
  }
112
134
 
113
- if((hands[a] == Player.STONE && hands[b] == Player.SCISSORS)
135
+ と、こんな風に書いて行けばいいのは分かりました。
114
136
 
115
- ||(hands[a] == Player.SCISSORS && hands[b] == Player.PAPER)
137
+ _____________________________
116
138
 
117
- ||(hands[a] == Player.PAPER && hands[b] == Player.STONE)){
139
+ うーん、欲を言えば、オブジェクト指向でこなしたいです。
118
140
 
119
-
120
-
121
- } else if((hands[b] == Player.STONE && hands[a] == Player.SCISSORS)
122
-
123
- ||(hands[b] == Player.SCISSORS && hands[a] == Player.PAPER)
124
-
125
- ||(hands[b] == Player.PAPER && hands[a] == Player.STONE)){
141
+ ヒントはもらっています。「ジャンケンの手をクラスにする」です。
126
-
127
- if(b == 0){
128
142
 
129
143
 
130
144
 
145
+ オブジェクト指向でジャンケンの手のクラスにすると、どうなりますが、
146
+
147
+ extends 継承を使うにはどのように変えたらいいですか?
148
+
131
- } else if(b == 1){
149
+ 今はジャンケンの手はフィールドですね。
132
150
 
133
151
 
134
-
135
- } else if(b == 2){
136
-
137
-
138
-
139
- }
140
-
141
- }
142
-
143
- }
144
-
145
-
146
-
147
- }
148
152
 
149
153
  /* if((player1hand == Player.STONE && player2hand == Player.SCISSORS)
150
154
 

2

書式の改善

2016/05/14 03:38

投稿

gyro16
gyro16

スコア89

test CHANGED
File without changes
test CHANGED
@@ -68,7 +68,7 @@
68
68
 
69
69
  for(int i = 0; i < hands.length; i++){
70
70
 
71
- for(int j = 0; j < hands.length ; j++){
71
+ for(int j = i + 1; j < hands.length ; j++){
72
72
 
73
73
  if(hands[i] != hands[j]){
74
74
 

1

文法の訂正

2016/05/14 01:19

投稿

gyro16
gyro16

スコア89

test CHANGED
File without changes
test CHANGED
@@ -66,7 +66,7 @@
66
66
 
67
67
  int maxType = 0;
68
68
 
69
- for(int i = 0; i < i < hands.length; i++){
69
+ for(int i = 0; i < hands.length; i++){
70
70
 
71
71
  for(int j = 0; j < hands.length ; j++){
72
72
 
@@ -81,6 +81,8 @@
81
81
  maxType = type;
82
82
 
83
83
  }
84
+
85
+ type = 1;
84
86
 
85
87
  }
86
88