質問編集履歴
1
解決
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,167 +1,7 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
|
-
|
3
|
-
mainクラスにPlaneクラス・BulletTrainクラスのspeedの値を渡したい。
|
4
2
|
|
5
3
|
### 発生している問題・エラーメッセージ
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
```
|
10
|
-
|
11
|
-
エラー: シンボルを見つけられません
|
12
|
-
|
13
|
-
int speed = player1.getSpeed();
|
14
|
-
|
15
|
-
^
|
16
|
-
|
17
|
-
シンボル: メソッド getSpeed()
|
18
|
-
|
19
|
-
場所: タイプPlayerの変数 player1
|
20
|
-
|
21
|
-
```
|
22
|
-
|
23
|
-
|
24
|
-
|
25
5
|
### 該当のソースコード
|
26
6
|
|
27
|
-
|
28
|
-
|
29
|
-
```ここに言語名を入力
|
30
|
-
|
31
|
-
class Viecle {
|
32
|
-
|
33
|
-
protected String name;
|
34
|
-
|
35
|
-
protected int gas;
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
public Viecle(String n, int g) {
|
40
|
-
|
41
|
-
name = n;
|
42
|
-
|
43
|
-
gas = g;
|
44
|
-
|
45
|
-
}
|
46
|
-
|
47
|
-
public Viecle() {
|
48
|
-
|
49
|
-
name = "";
|
50
|
-
|
51
|
-
gas = 0;
|
52
|
-
|
53
|
-
}
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
}
|
58
|
-
|
59
|
-
```
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
```
|
64
|
-
|
65
|
-
abstract class Player extends Viecle {
|
66
|
-
|
67
|
-
public Player(String n, int g) {
|
68
|
-
|
69
|
-
super(n, g);
|
70
|
-
|
71
|
-
}
|
72
|
-
|
73
|
-
abstract void play(Player p);
|
74
|
-
|
75
|
-
}
|
76
|
-
|
77
|
-
```
|
78
|
-
|
79
|
-
```
|
80
|
-
|
81
|
-
class Plane extends Player {
|
82
|
-
|
83
|
-
protected int speed;
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
public Plane(String n, int g) {
|
88
|
-
|
89
|
-
super(n, g);
|
90
|
-
|
91
|
-
}
|
92
|
-
|
93
|
-
public int getSpeed() {
|
94
|
-
|
95
|
-
return speed;
|
96
|
-
|
97
|
-
}
|
98
|
-
|
99
|
-
public void play(Player p) {
|
100
|
-
|
101
|
-
speed = (int) (Math.random()*10)+1;
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
}
|
106
|
-
|
107
|
-
```
|
108
|
-
|
109
|
-
```
|
110
|
-
|
111
|
-
class BulletTrain extends Player {
|
112
|
-
|
113
|
-
protected int speed;
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
public BulletTrain(String n, int g) {
|
118
|
-
|
119
|
-
super(n, g);
|
120
|
-
|
121
|
-
}
|
122
|
-
|
123
|
-
public int getSpeed() {
|
124
|
-
|
125
|
-
return speed;
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
public void play(Player p) {
|
130
|
-
|
131
|
-
speed = (int) (Math.random()*7)+1;
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
}
|
136
|
-
|
137
|
-
```
|
138
|
-
|
139
|
-
```
|
140
|
-
|
141
|
-
class Sample {
|
142
|
-
|
143
|
-
public static void main(String[] args) {
|
144
|
-
|
145
|
-
Player player1 = new Plane("1号", 200);
|
146
|
-
|
147
|
-
Player player2 = new BulletTrain("2号", 150);
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
int speed = player1.getSpeed();
|
152
|
-
|
153
|
-
player1.play(player2);
|
154
|
-
|
155
|
-
System.out.println(speed);
|
156
|
-
|
157
|
-
}
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
```
|
162
|
-
|
163
7
|
### 補足
|
164
|
-
|
165
|
-
エラー解決にアドバイスと仕組みを教えていただけると幸いです。
|
166
|
-
|
167
|
-
よろしくお願いいたします。
|