This commit is contained in:
2026-10-30 17:59:25 +09:00
parent 6feb026bb4
commit 6701bc351e
26 changed files with 254 additions and 39 deletions

View File

@@ -1,12 +1,8 @@
public interface Book {
String bookname;
//メソッドの定義
void bookPrint();
String chapter(String chapter1,String chapter2,String chapter3,String chapter4,String chapter5);
//Printメソッドの宣言
void Print();
}

View File

@@ -0,0 +1,4 @@
public interface Car {
void Print();
}

View File

@@ -1,9 +1,8 @@
public class Question14_01 {
public static void main(String[] args) {
Book book = new Book();
book.bookname = "プログラミング基礎入門";
Book bk = new programmingBook();
System.out.println(book.chapter());
bk.Print();
}
}

View File

@@ -0,0 +1,10 @@
public class Question14_02 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Car car = new Sportscar();
car.Print();
}
}

View File

@@ -0,0 +1,17 @@
public class Sportscar implements Car{
int gasolene = 100;
int speed = 301;
public void Print() {
System.out.println("ハイオクを" + gasolene +"リットル補充した");
if(speed >= 300) {
System.out.println("速度オーバーです");
} else {
System.out.println("スポーツカーは時速" + speed +"キロで走った");
}
}
}

View File

@@ -1,14 +1,12 @@
public class programmingBook implements Book {
String bookname;
public void bookPrint() {
System.out.println("プログラミング基礎入門");
//フィールド
String bookname = "プログラミング基礎入門";//本のタイトル
String[] chapter = {"式と変数","制御構文","メソッド","オブジェクト指向","継承"};//章立て(配列)
//コンストラクタ??
public void Print() {
System.out.println(bookname);
System.out.println(chapter[0] + chapter[1] + chapter[2] + chapter[3] + chapter[4]);
}
public String chapter(String chapter1,String chapter2,String chapter3,String chapter4,String chapter5) {
return chapter1+"/"+ chapter2 +"/"+ chapter3 +"/"+ chapter4 +"/"+ chapter5;
}
}