diff --git a/Question08-Method/src/main/java/Question08_06.java b/Question08-Method/src/main/java/Question08_06.java index c333d39..9489eec 100644 --- a/Question08-Method/src/main/java/Question08_06.java +++ b/Question08-Method/src/main/java/Question08_06.java @@ -1,17 +1,9 @@ public class Question08_06 { - - public static int addArray(int x, int y) { - return x,y; - } -} -} public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ - int x = 10; - int y = 20; - System.out.println(); - + + } } diff --git a/Question12-Encapsulation/src/main/java/Item.java b/Question12-Encapsulation/src/main/java/Item.java index 261834e..5c750d0 100644 --- a/Question12-Encapsulation/src/main/java/Item.java +++ b/Question12-Encapsulation/src/main/java/Item.java @@ -1,6 +1,6 @@ public class Item { - private String item = "アイテムA"; + private String item; // ゲッターセッターの設定 @@ -13,12 +13,8 @@ public class Item { } //コンストラクタの設定 - public Item(String item) { + Item(String item) { this.item = item; } - //メソッドの設定 - public void itembox() { - System.out.println(item); - } } diff --git a/Question12-Encapsulation/src/main/java/Question12_02.java b/Question12-Encapsulation/src/main/java/Question12_02.java index b6d8572..6e12cb9 100644 --- a/Question12-Encapsulation/src/main/java/Question12_02.java +++ b/Question12-Encapsulation/src/main/java/Question12_02.java @@ -4,10 +4,8 @@ public class Question12_02 { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ //インスタンスの生成 - Item secretitem = new Item(); + Item secretitem = new Item("アイテムA"); - secretitem.itembox(); - secretitem.setItem(); System.out.println(secretitem.getItem()); } diff --git a/Question14-Interface/src/main/java/Book.java b/Question14-Interface/src/main/java/Book.java index 7ffad47..8716dbd 100644 --- a/Question14-Interface/src/main/java/Book.java +++ b/Question14-Interface/src/main/java/Book.java @@ -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(); + } diff --git a/Question14-Interface/src/main/java/Car.java b/Question14-Interface/src/main/java/Car.java new file mode 100644 index 0000000..e7af741 --- /dev/null +++ b/Question14-Interface/src/main/java/Car.java @@ -0,0 +1,4 @@ + +public interface Car { + void Print(); +} diff --git a/Question14-Interface/src/main/java/Question14_01.java b/Question14-Interface/src/main/java/Question14_01.java index 8bbf90b..5fc9ce8 100644 --- a/Question14-Interface/src/main/java/Question14_01.java +++ b/Question14-Interface/src/main/java/Question14_01.java @@ -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(); } } diff --git a/Question14-Interface/src/main/java/Question14_02.java b/Question14-Interface/src/main/java/Question14_02.java new file mode 100644 index 0000000..8b72c77 --- /dev/null +++ b/Question14-Interface/src/main/java/Question14_02.java @@ -0,0 +1,10 @@ + +public class Question14_02 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Car car = new Sportscar(); + car.Print(); + } + +} diff --git a/Question14-Interface/src/main/java/Sportscar.java b/Question14-Interface/src/main/java/Sportscar.java new file mode 100644 index 0000000..d2dd43b --- /dev/null +++ b/Question14-Interface/src/main/java/Sportscar.java @@ -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 +"キロで走った"); + } + } + + +} diff --git a/Question14-Interface/src/main/java/programmingBook.java b/Question14-Interface/src/main/java/programmingBook.java index 237eb06..5d4f4ab 100644 --- a/Question14-Interface/src/main/java/programmingBook.java +++ b/Question14-Interface/src/main/java/programmingBook.java @@ -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; - } - } diff --git a/Question15-Polymorphism/.classpath b/Question15-Polymorphism/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question15-Polymorphism/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question15-Polymorphism/.gitignore b/Question15-Polymorphism/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question15-Polymorphism/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question15-Polymorphism/.project b/Question15-Polymorphism/.project new file mode 100644 index 0000000..0274b14 --- /dev/null +++ b/Question15-Polymorphism/.project @@ -0,0 +1,28 @@ + + + Question15-Polymorphism + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + + diff --git a/Question15-Polymorphism/.settings/org.eclipse.jdt.core.prefs b/Question15-Polymorphism/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question15-Polymorphism/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 +org.eclipse.jdt.core.compiler.compliance=21 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=21 diff --git a/Question15-Polymorphism/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question15-Polymorphism/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question15-Polymorphism/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question15-Polymorphism/src/main/java/Car.java b/Question15-Polymorphism/src/main/java/Car.java new file mode 100644 index 0000000..a894f0a --- /dev/null +++ b/Question15-Polymorphism/src/main/java/Car.java @@ -0,0 +1,11 @@ + +public class Car { + + //データ + String carname; + int carspeed; + + public void Car() { + System.out.println(carname + "は時速" + carspeed + "で走った"); + } +} diff --git a/Question15-Polymorphism/src/main/java/Question15_01.java b/Question15-Polymorphism/src/main/java/Question15_01.java new file mode 100644 index 0000000..6272654 --- /dev/null +++ b/Question15-Polymorphism/src/main/java/Question15_01.java @@ -0,0 +1,13 @@ + +public class Question15_01 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Car sc = new SportsCar(); + Car tk = new Truck(); + + sc.Car(); + tk.Car(); + } + +} diff --git a/Question15-Polymorphism/src/main/java/Question15_02.java b/Question15-Polymorphism/src/main/java/Question15_02.java new file mode 100644 index 0000000..97ebb70 --- /dev/null +++ b/Question15-Polymorphism/src/main/java/Question15_02.java @@ -0,0 +1,19 @@ + +public class Question15_02 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Car[] cr = new Car[2]; + + cr[0] = new SportsCar(); + cr[1] = new Truck(); + + + for(Car car1 : cr) { + car1.Car(); + } + + + + } +} diff --git a/Question15-Polymorphism/src/main/java/SportsCar.java b/Question15-Polymorphism/src/main/java/SportsCar.java new file mode 100644 index 0000000..e0066c7 --- /dev/null +++ b/Question15-Polymorphism/src/main/java/SportsCar.java @@ -0,0 +1,17 @@ + +public class SportsCar extends Car{ + + //データ + String carname = "スポーツカー"; + int carspeed = 100; + + @Override + public void Car() { + System.out.println(carname + "は時速" + carspeed + "で走った"); + } + + public void SportsCar() { + System.out.println(carname + "は時速" + (carspeed * 3) + "で走った"); + } +} + diff --git a/Question15-Polymorphism/src/main/java/Truck.java b/Question15-Polymorphism/src/main/java/Truck.java new file mode 100644 index 0000000..557793e --- /dev/null +++ b/Question15-Polymorphism/src/main/java/Truck.java @@ -0,0 +1,11 @@ + +public class Truck extends Car { + + //データ + String carname = "トラック"; + int carspeed = 30; + + public void Car() { + System.out.println(carname + "は時速" + carspeed + "で走った"); + } +} diff --git a/Question16-Exception/.classpath b/Question16-Exception/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question16-Exception/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question16-Exception/.gitignore b/Question16-Exception/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question16-Exception/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question16-Exception/.project b/Question16-Exception/.project new file mode 100644 index 0000000..16fb9ed --- /dev/null +++ b/Question16-Exception/.project @@ -0,0 +1,23 @@ + + + Question16-Exception + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + + diff --git a/Question16-Exception/.settings/org.eclipse.jdt.core.prefs b/Question16-Exception/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question16-Exception/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 +org.eclipse.jdt.core.compiler.compliance=21 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=21 diff --git a/Question16-Exception/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question16-Exception/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question16-Exception/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question16-Exception/src/main/java/Question16_01.java b/Question16-Exception/src/main/java/Question16_01.java new file mode 100644 index 0000000..4220b19 --- /dev/null +++ b/Question16-Exception/src/main/java/Question16_01.java @@ -0,0 +1,20 @@ + +public class Question16_01 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + //整数xとyを渡して、プログラムを呼び出す + + try { + int x = 10; + int y = 0; + int Caluculate; + Caluculate = x / y; + System.out.println(Caluculate); + } catch (ArithmeticException e) { + System.out.println("0で割ることはできません"); + } + + } + +} diff --git a/Question16-Exception/src/main/java/Question16_02.java b/Question16-Exception/src/main/java/Question16_02.java new file mode 100644 index 0000000..60d4a04 --- /dev/null +++ b/Question16-Exception/src/main/java/Question16_02.java @@ -0,0 +1,23 @@ + +public class Question16_02 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + + try { + String str = ""; + if(str.isEmpty()) + str = null; + } catch(NullPointerException e) { + System.out.println("入力が空です"); + } break; + + try { + int num = Integer.parseInt(str); + System.out.println(num*2); + } catch(NumberFormatException e) { + System.out.println("数値に変換できません"); + + +} +