This commit is contained in:
2026-10-27 16:48:43 +09:00
parent b6af93ba98
commit 6feb026bb4
42 changed files with 449 additions and 58 deletions

View File

@@ -0,0 +1,24 @@
import java.util.Random;
public class Car {
//フィールド
String color;
int gasoline;
//メソッド
public int run() {
this.gasoline = (gasoline -1);
if(gasoline >= 0) {
Random random = new Random();
int num = random.nextInt(16) + 1;
return num;
} else {
return -1;
}
}
}

View File

@@ -3,7 +3,18 @@ public class Question10_05 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
//インスタンス
Car car = new Car();
car.color = "赤";
car.gasoline = 50;
//runメソッドの実行
//car.run();
System.out.println(car.color +"色の車は" + car.run() +"進みました");
System.out.println(car.gasoline);
}
}