init
This commit is contained in:
21
Question15-Polymorphism/src/PTra15_01.java
Normal file
21
Question15-Polymorphism/src/PTra15_01.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* PTra15_01.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
public class PTra15_01 {
|
||||
public static void main(String[] args) {
|
||||
//※ この問題はcommonパッケージのクラスを使用して解いてください。
|
||||
// TODO SportsCar型のインスタンスをCar型の変数に代入してください
|
||||
|
||||
// TODO 作成したインスタンスのrunメソッドを実行してください。
|
||||
// ※ スポーツカーは時速100で走った と表示されれば正解
|
||||
|
||||
// TODO Truck型のインスタンスをCar型の変数に代入してください
|
||||
|
||||
// TODO 作成したインスタンスのrunメソッドを実行してください。
|
||||
// ※ トラックは時速30で走った
|
||||
|
||||
}
|
||||
}
|
||||
26
Question15-Polymorphism/src/PTra15_02.java
Normal file
26
Question15-Polymorphism/src/PTra15_02.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* PTra15_02.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
|
||||
public class PTra15_02 {
|
||||
public static void main(String[] args) {
|
||||
//※ この問題はcommonパッケージのクラスを使用して解いてください。
|
||||
// TODO SportsCar型のインスタンスをCar型の変数に代入してください
|
||||
|
||||
// TODO Truck型のインスタンスをCar型の変数に代入してください
|
||||
|
||||
// TODO Car型の配列を作成して、上記2つのインスタンスを追加してください
|
||||
|
||||
/* TODO carListの中身を順番に取り出して、runメソッドを実行してください。
|
||||
*
|
||||
* 以下が表示されれば正解
|
||||
*
|
||||
* スポーツカーは時速100で走った
|
||||
* トラックは時速30で走った
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
22
Question15-Polymorphism/src/PTra15_03.java
Normal file
22
Question15-Polymorphism/src/PTra15_03.java
Normal file
@@ -0,0 +1,22 @@
|
||||
import common.Car;
|
||||
import common.SportsCar;
|
||||
|
||||
/*
|
||||
* PTra15_03.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
|
||||
public class PTra15_03 {
|
||||
public static void main(String[] args) {
|
||||
//※ この問題はcommonパッケージのクラスを使用して解いてください。
|
||||
Car car = new SportsCar();
|
||||
|
||||
// TODO キャストを利用してSportsCarクラスに car 変数を代入してください。
|
||||
|
||||
// TODO turboメソッドを実行してください。
|
||||
// ※ スポーツカーは時速300で走った と表示されれば正解
|
||||
|
||||
}
|
||||
}
|
||||
41
Question15-Polymorphism/src/common/Car.java
Normal file
41
Question15-Polymorphism/src/common/Car.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
package common;
|
||||
|
||||
public class Car {
|
||||
|
||||
private String name;
|
||||
private int speed;
|
||||
|
||||
public Car(String name, int speed) {
|
||||
this.name = name;
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定されたスピードで走る
|
||||
*/
|
||||
public void run() {
|
||||
System.out.println(this.name + "は時速" + this.speed + "で走った");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public void setSpeed(int speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
}
|
||||
19
Question15-Polymorphism/src/common/SportsCar.java
Normal file
19
Question15-Polymorphism/src/common/SportsCar.java
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* PTra12_01.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
package common;
|
||||
|
||||
public class SportsCar extends Car{
|
||||
public SportsCar() {
|
||||
super("スポーツカー", 100);
|
||||
}
|
||||
/**
|
||||
* 設定されたスピードの3倍の速度で走る
|
||||
*/
|
||||
public void turbo() {
|
||||
System.out.println(super.getName() + "は時速" + (super.getSpeed() * 3 ) + "で走った");
|
||||
}
|
||||
}
|
||||
13
Question15-Polymorphism/src/common/Truck.java
Normal file
13
Question15-Polymorphism/src/common/Truck.java
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* PTra12_01.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
package common;
|
||||
|
||||
public class Truck extends Car{
|
||||
public Truck() {
|
||||
super("トラック", 30);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user