From c0101fc96dd29ceae75645c9296e93d3d986bb71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=B7=9D=E3=80=80=E8=A3=95=E6=A8=B9?= <26-y-ishikawa-stellatecnica@it-college.co.jp> Date: Fri, 30 Oct 2026 17:49:49 +0900 Subject: [PATCH] =?UTF-8?q?1030=E8=87=AA=E4=B8=BB=E5=AD=A6=E7=BF=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Question01-StartProgram/.project | 11 ++++ Question02-Expressions/.classpath | 6 ++ Question02-Expressions/.gitignore | 1 + Question02-Expressions/.project | 23 ++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 +++ ....eclipse.wst.common.project.facet.core.xml | 4 ++ .../src/main/java/Question2_1.java | 22 +++++++ .../src/main/java/Question2_2.java | 12 ++++ .../src/main/java/Question2_3.java | 11 ++++ .../src/main/java/Question2_4.java | 14 +++++ .../src/main/java/Question2_5.java | 13 +++++ .../src/main/java/Question2_6.java | 10 ++++ .../src/main/java/Question2_7.java | 10 ++++ .../src/main/java/Question2_8.java | 18 ++++++ Question03-if/.classpath | 6 ++ Question03-if/.gitignore | 1 + Question03-if/.project | 23 ++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 +++ ....eclipse.wst.common.project.facet.core.xml | 4 ++ Question03-if/src/main/java/Question3_1.java | 14 +++++ Question03-if/src/main/java/Question3_2.java | 15 +++++ Question03-if/src/main/java/Question3_3.java | 13 +++++ Question03-if/src/main/java/Question3_4.java | 22 +++++++ Question04-while/.classpath | 6 ++ Question04-while/.gitignore | 1 + Question04-while/.project | 23 ++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 +++ ....eclipse.wst.common.project.facet.core.xml | 4 ++ .../src/main/java/Question4_1.java | 13 +++++ .../src/main/java/Question4_2.java | 14 +++++ .../src/main/java/Question4_3.java | 20 +++++++ .../src/main/java/Question4_4.java | 33 +++++++++++ .../src/main/java/Question4_5.java | 53 +++++++++++++++++ Question05-switch/.classpath | 6 ++ Question05-switch/.gitignore | 1 + Question05-switch/.project | 23 ++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 +++ ....eclipse.wst.common.project.facet.core.xml | 4 ++ .../src/main/java/Question5_1.java | 36 ++++++++++++ .../src/main/java/Question5_2.java | 42 ++++++++++++++ .../src/main/java/Question5_3.java | 58 +++++++++++++++++++ Question06-for/.classpath | 6 ++ Question06-for/.gitignore | 1 + Question06-for/.project | 23 ++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 +++ ....eclipse.wst.common.project.facet.core.xml | 4 ++ Question06-for/src/main/java/Question6_1.java | 11 ++++ Question06-for/src/main/java/Question6_2.java | 13 +++++ Question06-for/src/main/java/Question6_3.java | 13 +++++ Question06-for/src/main/java/Question6_4.java | 19 ++++++ Question06-for/src/main/java/Question6_5.java | 14 +++++ Question06-for/src/main/java/Question6_6.java | 11 ++++ Question06-for/src/main/java/Question6_7.java | 14 +++++ Question07-Array/.classpath | 6 ++ Question07-Array/.gitignore | 1 + Question07-Array/.project | 23 ++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 +++ ....eclipse.wst.common.project.facet.core.xml | 4 ++ .../src/main/java/Question7_1.java | 9 +++ .../src/main/java/Question7_10.java | 16 +++++ .../src/main/java/Question7_2.java | 10 ++++ .../src/main/java/Question7_3.java | 12 ++++ .../src/main/java/Question7_4.java | 15 +++++ .../src/main/java/Question7_5.java | 11 ++++ .../src/main/java/Question7_6.java | 12 ++++ .../src/main/java/Question7_7.java | 28 +++++++++ .../src/main/java/Question7_8.java | 16 +++++ .../src/main/java/Question7_9.java | 23 ++++++++ Question08-Method/.classpath | 6 ++ Question08-Method/.gitignore | 1 + Question08-Method/.project | 23 ++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 +++ ....eclipse.wst.common.project.facet.core.xml | 4 ++ .../src/main/java/Question8_1.java | 12 ++++ .../src/main/java/Question8_2.java | 12 ++++ .../src/main/java/Question8_3.java | 13 +++++ .../src/main/java/Question8_4.java | 14 +++++ .../src/main/java/Question8_5.java | 27 +++++++++ .../src/main/java/Question8_6.java | 17 ++++++ .../src/main/java/Question8_7.java | 27 +++++++++ .../src/main/java/Question8_8.java | 25 ++++++++ Question09-Package/.classpath | 6 ++ Question09-Package/.gitignore | 1 + Question09-Package/.project | 23 ++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 +++ ....eclipse.wst.common.project.facet.core.xml | 4 ++ .../src/main/java/Question9_1.java | 9 +++ .../src/main/java/Question9_2.java | 9 +++ .../src/main/java/Question9_3.java | 9 +++ Question09-Package/src/main/java/Util.java | 6 ++ .../src/main/java/common/Util.java | 7 +++ Question10-InstanceAndClass/.classpath | 6 ++ Question10-InstanceAndClass/.gitignore | 1 + Question10-InstanceAndClass/.project | 23 ++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 +++ ....eclipse.wst.common.project.facet.core.xml | 4 ++ .../src/main/java/Calculation.java | 9 +++ .../src/main/java/Car.java | 17 ++++++ .../src/main/java/Question10_1.java | 15 +++++ .../src/main/java/Question10_2.java | 14 +++++ .../src/main/java/Question10_3.java | 19 ++++++ .../src/main/java/Question10_4.java | 16 +++++ .../src/main/java/Question10_5.java | 17 ++++++ .../src/main/java/Question10_6.java | 29 ++++++++++ .../src/main/java/Question10_7.java | 27 +++++++++ .../src/main/java/Question10_8.java | 49 ++++++++++++++++ .../src/main/java/Student.java | 7 +++ .../src/main/java/User.java | 10 ++++ Question11-ConstructorAndStatic/.classpath | 6 ++ Question11-ConstructorAndStatic/.gitignore | 1 + Question11-ConstructorAndStatic/.project | 23 ++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 +++ ....eclipse.wst.common.project.facet.core.xml | 4 ++ .../src/main/java/Atm.java | 14 +++++ .../src/main/java/Cat.java | 14 +++++ .../src/main/java/Jam.java | 8 +++ .../src/main/java/Question11_1.java | 19 ++++++ .../src/main/java/Question11_2.java | 17 ++++++ .../src/main/java/Question11_3.java | 13 +++++ .../src/main/java/Question11_4.java | 15 +++++ .../src/main/java/Question11_5.java | 12 ++++ .../src/main/java/Student.java | 14 +++++ .../src/main/java/Toast.java | 12 ++++ .../src/main/java/User.java | 16 +++++ .../src/main/java/Wallet.java | 4 ++ Question12-Encapsulation/.classpath | 6 ++ Question12-Encapsulation/.gitignore | 1 + Question12-Encapsulation/.project | 23 ++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 +++ ....eclipse.wst.common.project.facet.core.xml | 4 ++ .../src/main/java/Item.java | 8 +++ .../src/main/java/Question12_1.java | 18 ++++++ .../src/main/java/Question12_2.java | 10 ++++ .../src/main/java/User.java | 33 +++++++++++ Question13-Extends/.classpath | 6 ++ Question13-Extends/.gitignore | 1 + Question13-Extends/.project | 23 ++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 +++ ....eclipse.wst.common.project.facet.core.xml | 4 ++ Question13-Extends/src/main/java/Animal.java | 22 +++++++ Question13-Extends/src/main/java/Cat.java | 4 ++ .../src/main/java/Character.java | 53 +++++++++++++++++ Question13-Extends/src/main/java/Dog.java | 6 ++ Question13-Extends/src/main/java/Hero.java | 6 ++ Question13-Extends/src/main/java/Item.java | 28 +++++++++ .../src/main/java/Question13_1.java | 12 ++++ .../src/main/java/Question13_2.java | 12 ++++ .../src/main/java/Question13_3.java | 9 +++ .../src/main/java/Question13_4.java | 11 ++++ .../src/main/java/Question13_5.java | 26 +++++++++ .../src/main/java/Question13_6.java | 19 ++++++ .../src/main/java/Question13_7.java | 32 ++++++++++ Question13-Extends/src/main/java/Slime.java | 6 ++ .../src/main/java/SuperHero.java | 20 +++++++ Question14-Interface/.classpath | 6 ++ Question14-Interface/.gitignore | 1 + Question14-Interface/.project | 23 ++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 +++ ....eclipse.wst.common.project.facet.core.xml | 4 ++ Question14-Interface/src/main/java/Book.java | 6 ++ .../src/main/java/Book1_programming.java | 21 +++++++ Question14-Interface/src/main/java/Car.java | 5 ++ .../src/main/java/Question14_1.java | 11 ++++ .../src/main/java/Question14_2.java | 11 ++++ .../src/main/java/sportCar.java | 14 +++++ Question15-Polymorphism/.classpath | 6 ++ Question15-Polymorphism/.gitignore | 1 + Question15-Polymorphism/.project | 23 ++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 +++ ....eclipse.wst.common.project.facet.core.xml | 4 ++ .../src/main/java/Car.java | 14 +++++ .../src/main/java/Question15_1.java | 13 +++++ .../src/main/java/Question15_2.java | 17 ++++++ .../src/main/java/Question15_3.java | 10 ++++ .../src/main/java/SportsCar.java | 10 ++++ .../src/main/java/Truck.java | 8 +++ Question16-Exception/.classpath | 6 ++ Question16-Exception/.gitignore | 1 + Question16-Exception/.project | 23 ++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 +++ ....eclipse.wst.common.project.facet.core.xml | 4 ++ .../src/main/java/Question16_1.java | 19 ++++++ .../src/main/java/Question16_2.java | 32 ++++++++++ .../src/main/java/Question16_3.java | 30 ++++++++++ .../src/main/java/Question16_4.java | 25 ++++++++ .../src/main/java/testException.java | 6 ++ 186 files changed, 2507 insertions(+) create mode 100644 Question01-StartProgram/.project create mode 100644 Question02-Expressions/.classpath create mode 100644 Question02-Expressions/.gitignore create mode 100644 Question02-Expressions/.project create mode 100644 Question02-Expressions/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question02-Expressions/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question02-Expressions/src/main/java/Question2_1.java create mode 100644 Question02-Expressions/src/main/java/Question2_2.java create mode 100644 Question02-Expressions/src/main/java/Question2_3.java create mode 100644 Question02-Expressions/src/main/java/Question2_4.java create mode 100644 Question02-Expressions/src/main/java/Question2_5.java create mode 100644 Question02-Expressions/src/main/java/Question2_6.java create mode 100644 Question02-Expressions/src/main/java/Question2_7.java create mode 100644 Question02-Expressions/src/main/java/Question2_8.java create mode 100644 Question03-if/.classpath create mode 100644 Question03-if/.gitignore create mode 100644 Question03-if/.project create mode 100644 Question03-if/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question03-if/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question03-if/src/main/java/Question3_1.java create mode 100644 Question03-if/src/main/java/Question3_2.java create mode 100644 Question03-if/src/main/java/Question3_3.java create mode 100644 Question03-if/src/main/java/Question3_4.java create mode 100644 Question04-while/.classpath create mode 100644 Question04-while/.gitignore create mode 100644 Question04-while/.project create mode 100644 Question04-while/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question04-while/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question04-while/src/main/java/Question4_1.java create mode 100644 Question04-while/src/main/java/Question4_2.java create mode 100644 Question04-while/src/main/java/Question4_3.java create mode 100644 Question04-while/src/main/java/Question4_4.java create mode 100644 Question04-while/src/main/java/Question4_5.java create mode 100644 Question05-switch/.classpath create mode 100644 Question05-switch/.gitignore create mode 100644 Question05-switch/.project create mode 100644 Question05-switch/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question05-switch/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question05-switch/src/main/java/Question5_1.java create mode 100644 Question05-switch/src/main/java/Question5_2.java create mode 100644 Question05-switch/src/main/java/Question5_3.java create mode 100644 Question06-for/.classpath create mode 100644 Question06-for/.gitignore create mode 100644 Question06-for/.project create mode 100644 Question06-for/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question06-for/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question06-for/src/main/java/Question6_1.java create mode 100644 Question06-for/src/main/java/Question6_2.java create mode 100644 Question06-for/src/main/java/Question6_3.java create mode 100644 Question06-for/src/main/java/Question6_4.java create mode 100644 Question06-for/src/main/java/Question6_5.java create mode 100644 Question06-for/src/main/java/Question6_6.java create mode 100644 Question06-for/src/main/java/Question6_7.java create mode 100644 Question07-Array/.classpath create mode 100644 Question07-Array/.gitignore create mode 100644 Question07-Array/.project create mode 100644 Question07-Array/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question07-Array/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question07-Array/src/main/java/Question7_1.java create mode 100644 Question07-Array/src/main/java/Question7_10.java create mode 100644 Question07-Array/src/main/java/Question7_2.java create mode 100644 Question07-Array/src/main/java/Question7_3.java create mode 100644 Question07-Array/src/main/java/Question7_4.java create mode 100644 Question07-Array/src/main/java/Question7_5.java create mode 100644 Question07-Array/src/main/java/Question7_6.java create mode 100644 Question07-Array/src/main/java/Question7_7.java create mode 100644 Question07-Array/src/main/java/Question7_8.java create mode 100644 Question07-Array/src/main/java/Question7_9.java create mode 100644 Question08-Method/.classpath create mode 100644 Question08-Method/.gitignore create mode 100644 Question08-Method/.project create mode 100644 Question08-Method/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question08-Method/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question08-Method/src/main/java/Question8_1.java create mode 100644 Question08-Method/src/main/java/Question8_2.java create mode 100644 Question08-Method/src/main/java/Question8_3.java create mode 100644 Question08-Method/src/main/java/Question8_4.java create mode 100644 Question08-Method/src/main/java/Question8_5.java create mode 100644 Question08-Method/src/main/java/Question8_6.java create mode 100644 Question08-Method/src/main/java/Question8_7.java create mode 100644 Question08-Method/src/main/java/Question8_8.java create mode 100644 Question09-Package/.classpath create mode 100644 Question09-Package/.gitignore create mode 100644 Question09-Package/.project create mode 100644 Question09-Package/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question09-Package/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question09-Package/src/main/java/Question9_1.java create mode 100644 Question09-Package/src/main/java/Question9_2.java create mode 100644 Question09-Package/src/main/java/Question9_3.java create mode 100644 Question09-Package/src/main/java/Util.java create mode 100644 Question09-Package/src/main/java/common/Util.java create mode 100644 Question10-InstanceAndClass/.classpath create mode 100644 Question10-InstanceAndClass/.gitignore create mode 100644 Question10-InstanceAndClass/.project create mode 100644 Question10-InstanceAndClass/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question10-InstanceAndClass/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question10-InstanceAndClass/src/main/java/Calculation.java create mode 100644 Question10-InstanceAndClass/src/main/java/Car.java create mode 100644 Question10-InstanceAndClass/src/main/java/Question10_1.java create mode 100644 Question10-InstanceAndClass/src/main/java/Question10_2.java create mode 100644 Question10-InstanceAndClass/src/main/java/Question10_3.java create mode 100644 Question10-InstanceAndClass/src/main/java/Question10_4.java create mode 100644 Question10-InstanceAndClass/src/main/java/Question10_5.java create mode 100644 Question10-InstanceAndClass/src/main/java/Question10_6.java create mode 100644 Question10-InstanceAndClass/src/main/java/Question10_7.java create mode 100644 Question10-InstanceAndClass/src/main/java/Question10_8.java create mode 100644 Question10-InstanceAndClass/src/main/java/Student.java create mode 100644 Question10-InstanceAndClass/src/main/java/User.java create mode 100644 Question11-ConstructorAndStatic/.classpath create mode 100644 Question11-ConstructorAndStatic/.gitignore create mode 100644 Question11-ConstructorAndStatic/.project create mode 100644 Question11-ConstructorAndStatic/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question11-ConstructorAndStatic/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question11-ConstructorAndStatic/src/main/java/Atm.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Cat.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Jam.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Question11_1.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Question11_2.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Question11_3.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Question11_4.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Question11_5.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Student.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Toast.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/User.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Wallet.java create mode 100644 Question12-Encapsulation/.classpath create mode 100644 Question12-Encapsulation/.gitignore create mode 100644 Question12-Encapsulation/.project create mode 100644 Question12-Encapsulation/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question12-Encapsulation/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question12-Encapsulation/src/main/java/Item.java create mode 100644 Question12-Encapsulation/src/main/java/Question12_1.java create mode 100644 Question12-Encapsulation/src/main/java/Question12_2.java create mode 100644 Question12-Encapsulation/src/main/java/User.java create mode 100644 Question13-Extends/.classpath create mode 100644 Question13-Extends/.gitignore create mode 100644 Question13-Extends/.project create mode 100644 Question13-Extends/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question13-Extends/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question13-Extends/src/main/java/Animal.java create mode 100644 Question13-Extends/src/main/java/Cat.java create mode 100644 Question13-Extends/src/main/java/Character.java create mode 100644 Question13-Extends/src/main/java/Dog.java create mode 100644 Question13-Extends/src/main/java/Hero.java create mode 100644 Question13-Extends/src/main/java/Item.java create mode 100644 Question13-Extends/src/main/java/Question13_1.java create mode 100644 Question13-Extends/src/main/java/Question13_2.java create mode 100644 Question13-Extends/src/main/java/Question13_3.java create mode 100644 Question13-Extends/src/main/java/Question13_4.java create mode 100644 Question13-Extends/src/main/java/Question13_5.java create mode 100644 Question13-Extends/src/main/java/Question13_6.java create mode 100644 Question13-Extends/src/main/java/Question13_7.java create mode 100644 Question13-Extends/src/main/java/Slime.java create mode 100644 Question13-Extends/src/main/java/SuperHero.java create mode 100644 Question14-Interface/.classpath create mode 100644 Question14-Interface/.gitignore create mode 100644 Question14-Interface/.project create mode 100644 Question14-Interface/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question14-Interface/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question14-Interface/src/main/java/Book.java create mode 100644 Question14-Interface/src/main/java/Book1_programming.java create mode 100644 Question14-Interface/src/main/java/Car.java create mode 100644 Question14-Interface/src/main/java/Question14_1.java create mode 100644 Question14-Interface/src/main/java/Question14_2.java create mode 100644 Question14-Interface/src/main/java/sportCar.java create mode 100644 Question15-Polymorphism/.classpath create mode 100644 Question15-Polymorphism/.gitignore create mode 100644 Question15-Polymorphism/.project create mode 100644 Question15-Polymorphism/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question15-Polymorphism/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question15-Polymorphism/src/main/java/Car.java create mode 100644 Question15-Polymorphism/src/main/java/Question15_1.java create mode 100644 Question15-Polymorphism/src/main/java/Question15_2.java create mode 100644 Question15-Polymorphism/src/main/java/Question15_3.java create mode 100644 Question15-Polymorphism/src/main/java/SportsCar.java create mode 100644 Question15-Polymorphism/src/main/java/Truck.java create mode 100644 Question16-Exception/.classpath create mode 100644 Question16-Exception/.gitignore create mode 100644 Question16-Exception/.project create mode 100644 Question16-Exception/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question16-Exception/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question16-Exception/src/main/java/Question16_1.java create mode 100644 Question16-Exception/src/main/java/Question16_2.java create mode 100644 Question16-Exception/src/main/java/Question16_3.java create mode 100644 Question16-Exception/src/main/java/Question16_4.java create mode 100644 Question16-Exception/src/main/java/testException.java diff --git a/Question01-StartProgram/.project b/Question01-StartProgram/.project new file mode 100644 index 0000000..832c9ea --- /dev/null +++ b/Question01-StartProgram/.project @@ -0,0 +1,11 @@ + + + Question01-StartProgram + + + + + + + + diff --git a/Question02-Expressions/.classpath b/Question02-Expressions/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question02-Expressions/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question02-Expressions/.gitignore b/Question02-Expressions/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question02-Expressions/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question02-Expressions/.project b/Question02-Expressions/.project new file mode 100644 index 0000000..8333c1b --- /dev/null +++ b/Question02-Expressions/.project @@ -0,0 +1,23 @@ + + + Question02-Expressions + + + + + + 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/Question02-Expressions/.settings/org.eclipse.jdt.core.prefs b/Question02-Expressions/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question02-Expressions/.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/Question02-Expressions/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question02-Expressions/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question02-Expressions/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question02-Expressions/src/main/java/Question2_1.java b/Question02-Expressions/src/main/java/Question2_1.java new file mode 100644 index 0000000..c37417d --- /dev/null +++ b/Question02-Expressions/src/main/java/Question2_1.java @@ -0,0 +1,22 @@ + +public class Question2_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int sum = (6 + 2); + System.out.println(sum); + + int diff = (6 - 2); + System.out.println(diff); + + int mulch = (6 * 2); + System.out.println(mulch); + + int div = (6 / 2); + System.out.println(div); + + int rem = (17 % 5); + System.out.println(rem); + } + +} diff --git a/Question02-Expressions/src/main/java/Question2_2.java b/Question02-Expressions/src/main/java/Question2_2.java new file mode 100644 index 0000000..32c79f7 --- /dev/null +++ b/Question02-Expressions/src/main/java/Question2_2.java @@ -0,0 +1,12 @@ + +public class Question2_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + String lastName = "山田"; + String firstName = "太郎"; + + System.out.println(lastName + firstName); + } + +} diff --git a/Question02-Expressions/src/main/java/Question2_3.java b/Question02-Expressions/src/main/java/Question2_3.java new file mode 100644 index 0000000..72b7a47 --- /dev/null +++ b/Question02-Expressions/src/main/java/Question2_3.java @@ -0,0 +1,11 @@ + +public class Question2_3 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int num = 10; + num += 5; + System.out.println(num); + } + +} diff --git a/Question02-Expressions/src/main/java/Question2_4.java b/Question02-Expressions/src/main/java/Question2_4.java new file mode 100644 index 0000000..e8cabbe --- /dev/null +++ b/Question02-Expressions/src/main/java/Question2_4.java @@ -0,0 +1,14 @@ + +public class Question2_4 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + float sum; + int num = 10; + float fl= 3.14f; + + sum = num + fl; + System.out.println(sum); + } + +} diff --git a/Question02-Expressions/src/main/java/Question2_5.java b/Question02-Expressions/src/main/java/Question2_5.java new file mode 100644 index 0000000..b9f83cd --- /dev/null +++ b/Question02-Expressions/src/main/java/Question2_5.java @@ -0,0 +1,13 @@ + +public class Question2_5 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int age = 20; + int diff = 5; + + System.out.println("山田さんは" + age + "歳です。"); + System.out.println(diff + "年後には" + (age + diff) + "歳になります。"); + } + +} diff --git a/Question02-Expressions/src/main/java/Question2_6.java b/Question02-Expressions/src/main/java/Question2_6.java new file mode 100644 index 0000000..360971a --- /dev/null +++ b/Question02-Expressions/src/main/java/Question2_6.java @@ -0,0 +1,10 @@ + +public class Question2_6 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + float sum = 9f / 2f; + System.out.println(sum); + } + +} diff --git a/Question02-Expressions/src/main/java/Question2_7.java b/Question02-Expressions/src/main/java/Question2_7.java new file mode 100644 index 0000000..254c9b9 --- /dev/null +++ b/Question02-Expressions/src/main/java/Question2_7.java @@ -0,0 +1,10 @@ + +public class Question2_7 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int num = (int)1.0; + System.out.println(num); + } + +} diff --git a/Question02-Expressions/src/main/java/Question2_8.java b/Question02-Expressions/src/main/java/Question2_8.java new file mode 100644 index 0000000..0029a7a --- /dev/null +++ b/Question02-Expressions/src/main/java/Question2_8.java @@ -0,0 +1,18 @@ + +public class Question2_8 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int money = 1000; + int price = 580; + float taxRate = 0.08f; + + float tax = (int) (price * taxRate); + + float total = price + tax; + money -= total; + + System.out.println("残金は" + money + "円です。"); + } + +} diff --git a/Question03-if/.classpath b/Question03-if/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question03-if/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question03-if/.gitignore b/Question03-if/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question03-if/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question03-if/.project b/Question03-if/.project new file mode 100644 index 0000000..1c2475e --- /dev/null +++ b/Question03-if/.project @@ -0,0 +1,23 @@ + + + Question03-if + + + + + + 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/Question03-if/.settings/org.eclipse.jdt.core.prefs b/Question03-if/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question03-if/.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/Question03-if/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question03-if/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question03-if/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question03-if/src/main/java/Question3_1.java b/Question03-if/src/main/java/Question3_1.java new file mode 100644 index 0000000..1a85a38 --- /dev/null +++ b/Question03-if/src/main/java/Question3_1.java @@ -0,0 +1,14 @@ + +public class Question3_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + //設問1 + int num; + num = 100; + if(num == 100) { + System.out.println("条件に合致しました"); + } + } + +} diff --git a/Question03-if/src/main/java/Question3_2.java b/Question03-if/src/main/java/Question3_2.java new file mode 100644 index 0000000..c7ea05f --- /dev/null +++ b/Question03-if/src/main/java/Question3_2.java @@ -0,0 +1,15 @@ + +public class Question3_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int num; + num = 65; + if(num >= 65) { + System.out.println("合格です"); + }else if(num < 65) { + System.out.println("不合格です"); + } + } + +} diff --git a/Question03-if/src/main/java/Question3_3.java b/Question03-if/src/main/java/Question3_3.java new file mode 100644 index 0000000..d3fd162 --- /dev/null +++ b/Question03-if/src/main/java/Question3_3.java @@ -0,0 +1,13 @@ + +public class Question3_3 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int num; + num = 10; + if (num % 2 == 0 && num % 5 == 0) { + System.out.println(num + "は2でも5でも割り切れます。"); + } + } + +} diff --git a/Question03-if/src/main/java/Question3_4.java b/Question03-if/src/main/java/Question3_4.java new file mode 100644 index 0000000..6f389c5 --- /dev/null +++ b/Question03-if/src/main/java/Question3_4.java @@ -0,0 +1,22 @@ +import java.util.Scanner; + +public class Question3_4 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + System.out.println("降水確率を入力してください。(数字のみ)"); + Scanner sc = new Scanner(System.in); + int num = sc.nextInt(); + + if(num < 0 || num >100){ + System.out.println("不正な値が入力されました"); + }else if(num >= 75) { + System.out.println("雨が降る確率が高いです"); + }else if(num >= 30 && num <75) { + System.out.println("雨が降るかもしれないです"); + }else if (num < 30) { + System.out.println("雨はまず降らないでしょう"); + } + } + +} diff --git a/Question04-while/.classpath b/Question04-while/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question04-while/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question04-while/.gitignore b/Question04-while/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question04-while/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question04-while/.project b/Question04-while/.project new file mode 100644 index 0000000..29bdff7 --- /dev/null +++ b/Question04-while/.project @@ -0,0 +1,23 @@ + + + Question04-while + + + + + + 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/Question04-while/.settings/org.eclipse.jdt.core.prefs b/Question04-while/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question04-while/.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/Question04-while/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question04-while/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question04-while/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question04-while/src/main/java/Question4_1.java b/Question04-while/src/main/java/Question4_1.java new file mode 100644 index 0000000..3ead79f --- /dev/null +++ b/Question04-while/src/main/java/Question4_1.java @@ -0,0 +1,13 @@ + +public class Question4_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int num = 0; + + while(num != 5) { + num = (int)(Math.random()*10); + System.out.println(num); + } + } +} diff --git a/Question04-while/src/main/java/Question4_2.java b/Question04-while/src/main/java/Question4_2.java new file mode 100644 index 0000000..effb0bb --- /dev/null +++ b/Question04-while/src/main/java/Question4_2.java @@ -0,0 +1,14 @@ + +public class Question4_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int num = 2; + + while(num < 1000) { + num *= 2; + System.out.println(num); + } + } + +} diff --git a/Question04-while/src/main/java/Question4_3.java b/Question04-while/src/main/java/Question4_3.java new file mode 100644 index 0000000..4c548e6 --- /dev/null +++ b/Question04-while/src/main/java/Question4_3.java @@ -0,0 +1,20 @@ + +public class Question4_3 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int num = 0; + + while(true) { + num = (int)(Math.random()*10); + if(num !=5) { + System.out.println(num); + continue; + }else { + System.out.println(num); + break; + } + } + } + +} diff --git a/Question04-while/src/main/java/Question4_4.java b/Question04-while/src/main/java/Question4_4.java new file mode 100644 index 0000000..c4c04e8 --- /dev/null +++ b/Question04-while/src/main/java/Question4_4.java @@ -0,0 +1,33 @@ +import java.util.Scanner; + +public class Question4_4 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int map = 50; + int progress = 0; + int num = 0; + String str; + + System.out.println("===== START ====="); + + while(progress <= map) { + System.out.println("Enterキーを押してください。さいころをふります。"); + Scanner sc = new Scanner(System.in); + str = sc.nextLine(); + System.out.println(str); + + num = (int)(Math.random()*6) + 1; + System.out.println(num + "の目がでました。"); + + progress += num; + int remaining = map - progress; + if(progress < map) { + System.out.println("残りのマスは" + remaining + "マスです。"); + } + } + + System.out.println("===== GOAL ====="); + } + +} diff --git a/Question04-while/src/main/java/Question4_5.java b/Question04-while/src/main/java/Question4_5.java new file mode 100644 index 0000000..bfa26a1 --- /dev/null +++ b/Question04-while/src/main/java/Question4_5.java @@ -0,0 +1,53 @@ +import java.util.Scanner; + +public class Question4_5 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + boolean winFlag = false; + + while(!winFlag) { + System.out.println("じゃんけんを行います。"); + System.out.println("あなたの出す手を入力してください。"); + System.out.println("0:グー、1:チョキ、2:パー"); + + Scanner sc = new Scanner(System.in); + int playerHand; + playerHand= sc.nextInt(); + System.out.println(playerHand); + + if(playerHand == 0) { + System.out.println("あなたはグーを出しました。"); + }else if(playerHand == 1) { + System.out.println("あなたはチョキを出しました。"); + }else { + System.out.println("あなたはパーを出しました。"); + } + + int num = (int)(Math.random()*3); + int npcHand = num; + + if(npcHand ==0) { + System.out.println("相手はグーを出しました。"); + }else if(npcHand ==1) { + System.out.println("相手はチョキを出しました。"); + }else { + System.out.println("相手はパーを出しました。"); + } + + if(playerHand == 0 && npcHand ==1 || playerHand == 1 && npcHand ==2 || playerHand == 2 &&npcHand ==0) { + System.out.println("あなたの勝ちです。"); + winFlag = true; + }else if(playerHand == npcHand) { + System.out.println("あいこです。"); + System.out.println(); + continue; + }else { + System.out.println("あなたの負けです。"); + System.out.println(); + continue; + } + + } +} +} diff --git a/Question05-switch/.classpath b/Question05-switch/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question05-switch/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question05-switch/.gitignore b/Question05-switch/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question05-switch/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question05-switch/.project b/Question05-switch/.project new file mode 100644 index 0000000..9607eea --- /dev/null +++ b/Question05-switch/.project @@ -0,0 +1,23 @@ + + + Question05-switch + + + + + + 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/Question05-switch/.settings/org.eclipse.jdt.core.prefs b/Question05-switch/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question05-switch/.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/Question05-switch/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question05-switch/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question05-switch/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question05-switch/src/main/java/Question5_1.java b/Question05-switch/src/main/java/Question5_1.java new file mode 100644 index 0000000..333e8e2 --- /dev/null +++ b/Question05-switch/src/main/java/Question5_1.java @@ -0,0 +1,36 @@ + +public class Question5_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + System.out.println("今日の運勢を占います。"); + int num = (int)(Math.random()*6); + + switch(num) { + case 0: + System.out.println("あなたの運勢は「大吉」です"); + break; + + case 1: + System.out.println("あなたの運勢は「吉」です"); + break; + + case 2: + System.out.println("あなたの運勢は「中吉」"); + break; + + case 3: + System.out.println("あなたの運勢は「小吉」"); + break; + + case 4: + System.out.println("あなたの運勢は「末吉」"); + break; + + case 5: + System.out.println("あなたの運勢は「凶」"); + break; + } + } + +} diff --git a/Question05-switch/src/main/java/Question5_2.java b/Question05-switch/src/main/java/Question5_2.java new file mode 100644 index 0000000..572e52e --- /dev/null +++ b/Question05-switch/src/main/java/Question5_2.java @@ -0,0 +1,42 @@ +import java.util.Scanner; + +public class Question5_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + System.out.println("1つ目の数値を入力してください"); + Scanner sc = new Scanner(System.in); + int num1 = sc.nextInt(); + System.out.println("2つ目の数値を入力してください"); + int num2 = sc.nextInt(); + System.out.println("計算方法を選択してください"); + sc.nextLine(); + String choice = sc.nextLine(); + + switch(choice) { + case "+": + System.out.println(num1 + num2); + break; + + case "-": + System.out.println(num1 - num2); + break; + + case "*": + System.out.println(num1 * num2); + break; + + case "/": + System.out.println(num1 / num2); + break; + + case "%": + System.out.println(num1 % num2); + break; + + default: + System.out.println("計算に失敗しました"); + } + } + +} diff --git a/Question05-switch/src/main/java/Question5_3.java b/Question05-switch/src/main/java/Question5_3.java new file mode 100644 index 0000000..131da5c --- /dev/null +++ b/Question05-switch/src/main/java/Question5_3.java @@ -0,0 +1,58 @@ +import java.util.Scanner; + +public class Question5_3 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + System.out.println("========================================="); + System.out.println(" ゲームの説明 "); + System.out.println("========================================="); + + System.out.println("これからハイ&ローゲームを行います。"); + System.out.println("ハイ&ローゲームは、あなたのカードがディーラーのカードより大きいか小さいかを予想するゲームです。"); + System.out.println(); + + System.out.println("========================================="); + System.out.println(" ゲーム開始 "); + System.out.println("========================================="); + + + int dealerCard = (int)(Math.random()*13)+1; + System.out.println("ディーラーのカードは" + dealerCard + "です"); + int myCard = (int)(Math.random()*13)+1; + System.out.println(); + System.out.println("あなたのカードがディーラのカードより大きい場合は H 小さい場合は L を入力してください。"); + System.out.println("※ カードの数値が同じ場合はあなたの勝ちです。"); + Scanner sc = new Scanner(System.in); + String judgement = sc.nextLine(); + System.out.println("あなたのカードは" + myCard + "です"); + + + System.out.println(); + System.out.println("========================================="); + System.out.println(" 勝敗判定" ); + System.out.println("========================================="); + + switch(judgement) { + case "H": + if(myCard > dealerCard || myCard == dealerCard) { + System.out.println("あなたの勝ちです"); + break; + }else{ + System.out.println("あなたの負けです"); + break; + } + case "L": + if(myCard < dealerCard || myCard == dealerCard) { + System.out.println("あなたの勝ちです"); + break; + }else{ + System.out.println("あなたの負けです"); + break; + } + default: + System.out.println("不正な値が入力されました"); + } + } + +} diff --git a/Question06-for/.classpath b/Question06-for/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question06-for/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question06-for/.gitignore b/Question06-for/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question06-for/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question06-for/.project b/Question06-for/.project new file mode 100644 index 0000000..a03f44a --- /dev/null +++ b/Question06-for/.project @@ -0,0 +1,23 @@ + + + Question06-for + + + + + + 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/Question06-for/.settings/org.eclipse.jdt.core.prefs b/Question06-for/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question06-for/.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/Question06-for/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question06-for/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question06-for/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question06-for/src/main/java/Question6_1.java b/Question06-for/src/main/java/Question6_1.java new file mode 100644 index 0000000..0a0d724 --- /dev/null +++ b/Question06-for/src/main/java/Question6_1.java @@ -0,0 +1,11 @@ + +public class Question6_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + for(int i = 0; i < 100; i++){ + System.out.println(i); + } + } + +} diff --git a/Question06-for/src/main/java/Question6_2.java b/Question06-for/src/main/java/Question6_2.java new file mode 100644 index 0000000..f4c8798 --- /dev/null +++ b/Question06-for/src/main/java/Question6_2.java @@ -0,0 +1,13 @@ + +public class Question6_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + System.out.println("■■■■■"); + + for(int i = 0; i < 5;i++) { + System.out.print("■"); + } + } + +} diff --git a/Question06-for/src/main/java/Question6_3.java b/Question06-for/src/main/java/Question6_3.java new file mode 100644 index 0000000..825aa22 --- /dev/null +++ b/Question06-for/src/main/java/Question6_3.java @@ -0,0 +1,13 @@ + +public class Question6_3 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + for(int i = 0;i < 100; i++) { + if(i % 2 == 0) { + System.out.println(i); + } + } + } + +} diff --git a/Question06-for/src/main/java/Question6_4.java b/Question06-for/src/main/java/Question6_4.java new file mode 100644 index 0000000..c56daf8 --- /dev/null +++ b/Question06-for/src/main/java/Question6_4.java @@ -0,0 +1,19 @@ + +public class Question6_4 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + for(int i = 1; i <= 49; i++) { + if(i % 3 == 0 && i % 5 == 0) { + System.out.println("fizzbuzz"); + }else if(i % 5 == 0) { + System.out.println("buzz"); + }else if(i % 3 == 0 ) { + System.out.println("fizz"); + }else { + System.out.println(i); + } + } + } + +} diff --git a/Question06-for/src/main/java/Question6_5.java b/Question06-for/src/main/java/Question6_5.java new file mode 100644 index 0000000..c0b8925 --- /dev/null +++ b/Question06-for/src/main/java/Question6_5.java @@ -0,0 +1,14 @@ + +public class Question6_5 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + for(int i = 0; i < 10; i++) { + int num = (int)(Math.random()*3); + if(num !=2) { + System.out.println(num); + } + } + } + +} diff --git a/Question06-for/src/main/java/Question6_6.java b/Question06-for/src/main/java/Question6_6.java new file mode 100644 index 0000000..ff87f0f --- /dev/null +++ b/Question06-for/src/main/java/Question6_6.java @@ -0,0 +1,11 @@ + +public class Question6_6 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + for(int i = 0; i < 5; i++) { + System.out.println("■■■■■"); + } + } + +} diff --git a/Question06-for/src/main/java/Question6_7.java b/Question06-for/src/main/java/Question6_7.java new file mode 100644 index 0000000..3dcb5b7 --- /dev/null +++ b/Question06-for/src/main/java/Question6_7.java @@ -0,0 +1,14 @@ + +public class Question6_7 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + for(int i = 1; i <= 9; i++) { + for(int j = 1; j <= 9; j++) { + System.out.printf("%2d",i * j); + } + System.out.println(); + } + } + +} diff --git a/Question07-Array/.classpath b/Question07-Array/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question07-Array/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question07-Array/.gitignore b/Question07-Array/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question07-Array/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question07-Array/.project b/Question07-Array/.project new file mode 100644 index 0000000..57cefa4 --- /dev/null +++ b/Question07-Array/.project @@ -0,0 +1,23 @@ + + + Question07-Array + + + + + + 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/Question07-Array/.settings/org.eclipse.jdt.core.prefs b/Question07-Array/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question07-Array/.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/Question07-Array/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question07-Array/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question07-Array/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question07-Array/src/main/java/Question7_1.java b/Question07-Array/src/main/java/Question7_1.java new file mode 100644 index 0000000..8ca430f --- /dev/null +++ b/Question07-Array/src/main/java/Question7_1.java @@ -0,0 +1,9 @@ + +public class Question7_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int[] nums = {1, 3, 5, 7, 9}; + System.out.println(nums[1]); + } +} diff --git a/Question07-Array/src/main/java/Question7_10.java b/Question07-Array/src/main/java/Question7_10.java new file mode 100644 index 0000000..1489d1c --- /dev/null +++ b/Question07-Array/src/main/java/Question7_10.java @@ -0,0 +1,16 @@ + +public class Question7_10 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int[] nums = new int[100]; + + for(int i = 0; i < nums.length; i++) { + nums[i] = i + 1; + } + for(int i = 0; i < nums.length; i++) { + System.out.println(nums[i]); + } + } + +} diff --git a/Question07-Array/src/main/java/Question7_2.java b/Question07-Array/src/main/java/Question7_2.java new file mode 100644 index 0000000..30a144f --- /dev/null +++ b/Question07-Array/src/main/java/Question7_2.java @@ -0,0 +1,10 @@ + +public class Question7_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int[] nums = {1, 10, 100}; + System.out.println(nums[0] + nums[2]); + } + +} diff --git a/Question07-Array/src/main/java/Question7_3.java b/Question07-Array/src/main/java/Question7_3.java new file mode 100644 index 0000000..3a03d9b --- /dev/null +++ b/Question07-Array/src/main/java/Question7_3.java @@ -0,0 +1,12 @@ + +public class Question7_3 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + String[] str = {"森", "山", "沼", "島", "平地"}; + for(int i = 0; i <= 4; i++) { + System.out.println(str[i]); + } + } + +} diff --git a/Question07-Array/src/main/java/Question7_4.java b/Question07-Array/src/main/java/Question7_4.java new file mode 100644 index 0000000..5fb9ac7 --- /dev/null +++ b/Question07-Array/src/main/java/Question7_4.java @@ -0,0 +1,15 @@ + +public class Question7_4 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int[] nums = new int[1000]; + for(int i = 0; i < 1000; i++) { + nums[i] = i + 1; + } + for(int i = 0; i < 1000; i++) { + System.out.println(nums[i]); + } + +} +} \ No newline at end of file diff --git a/Question07-Array/src/main/java/Question7_5.java b/Question07-Array/src/main/java/Question7_5.java new file mode 100644 index 0000000..9b8e240 --- /dev/null +++ b/Question07-Array/src/main/java/Question7_5.java @@ -0,0 +1,11 @@ + +public class Question7_5 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + String[] str = {"森", "山", "沼", "島", "平地"}; + int num = (int)(Math.random()*5); + System.out.println(str[num]); + } + +} diff --git a/Question07-Array/src/main/java/Question7_6.java b/Question07-Array/src/main/java/Question7_6.java new file mode 100644 index 0000000..bf08f47 --- /dev/null +++ b/Question07-Array/src/main/java/Question7_6.java @@ -0,0 +1,12 @@ + +public class Question7_6 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + String[] str = {"森", "山", "沼", "島", "平地"}; + for(int i = 4; i >=0; i--) { + System.out.println(str[i]); + } + +} +} \ No newline at end of file diff --git a/Question07-Array/src/main/java/Question7_7.java b/Question07-Array/src/main/java/Question7_7.java new file mode 100644 index 0000000..68ee84e --- /dev/null +++ b/Question07-Array/src/main/java/Question7_7.java @@ -0,0 +1,28 @@ + +public class Question7_7 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + String[][] timetable = { + {"国語", "社会", "国語", "理科", "社会"}, + {"英語", "数学", "英語", "数学", "国語"}, + {"理科", "国語", "理科", "国語" ,"理科"}, + {"社会", "社会", "数学", "社会", "数学"}, + {"数学", "英語", "英語", "理科", "英語"}, + }; + + System.out.println("\t 月\t 火\t 水\t 木\t 金"); + for(int i = 0; i < 5; i++) { + System.out.print((i + 1) + "時間目"); + + for(int j = 0; j < 5; j++) { + System.out.print("\t" + timetable[i][j]); + } + System.out.println(); + } + + System.out.println(timetable[1][4]); + } + } + + diff --git a/Question07-Array/src/main/java/Question7_8.java b/Question07-Array/src/main/java/Question7_8.java new file mode 100644 index 0000000..edbe88f --- /dev/null +++ b/Question07-Array/src/main/java/Question7_8.java @@ -0,0 +1,16 @@ + +public class Question7_8 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int[][] nums = { + {1, 3, 5, 7}, + {11, 13, 17, 19, 23, 29} + }; + for(int i = 0; i < nums.length; i++) { + for(int j = 0; j < nums[i].length; j++) { + System.out.println(nums[i][j]); + } + } + } +} diff --git a/Question07-Array/src/main/java/Question7_9.java b/Question07-Array/src/main/java/Question7_9.java new file mode 100644 index 0000000..0b93aa1 --- /dev/null +++ b/Question07-Array/src/main/java/Question7_9.java @@ -0,0 +1,23 @@ + +public class Question7_9 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int[][] nums = { + {1, 3, 5, 7}, + {11, 13, 17, 19, 23, 29} + }; + int sum = 0; + int count = 0; + + for(int i = 0; i < nums.length; i++) { + for(int j = 0; j < nums[i].length; j++) { + sum += nums[i][j]; + count++; + } + } + float ave = (float)sum / count; + System.out.println(ave); + } + +} diff --git a/Question08-Method/.classpath b/Question08-Method/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question08-Method/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question08-Method/.gitignore b/Question08-Method/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question08-Method/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question08-Method/.project b/Question08-Method/.project new file mode 100644 index 0000000..f2ff099 --- /dev/null +++ b/Question08-Method/.project @@ -0,0 +1,23 @@ + + + Question08-Method + + + + + + 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/Question08-Method/.settings/org.eclipse.jdt.core.prefs b/Question08-Method/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question08-Method/.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/Question08-Method/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question08-Method/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question08-Method/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question08-Method/src/main/java/Question8_1.java b/Question08-Method/src/main/java/Question8_1.java new file mode 100644 index 0000000..5561e24 --- /dev/null +++ b/Question08-Method/src/main/java/Question8_1.java @@ -0,0 +1,12 @@ + +public class Question8_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + hello(); + } + + public static void hello() { + System.out.println("こんにちは"); + } +} diff --git a/Question08-Method/src/main/java/Question8_2.java b/Question08-Method/src/main/java/Question8_2.java new file mode 100644 index 0000000..bcca261 --- /dev/null +++ b/Question08-Method/src/main/java/Question8_2.java @@ -0,0 +1,12 @@ + +public class Question8_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + hello("山田"); + } + + public static void hello(String str) { + System.out.println("こんにちは" + str + "です"); + } +} diff --git a/Question08-Method/src/main/java/Question8_3.java b/Question08-Method/src/main/java/Question8_3.java new file mode 100644 index 0000000..2450138 --- /dev/null +++ b/Question08-Method/src/main/java/Question8_3.java @@ -0,0 +1,13 @@ + +public class Question8_3 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + String str = hello(); + System.out.println(str); + } + + public static String hello() { + return "こんにちは"; + } +} diff --git a/Question08-Method/src/main/java/Question8_4.java b/Question08-Method/src/main/java/Question8_4.java new file mode 100644 index 0000000..b66e053 --- /dev/null +++ b/Question08-Method/src/main/java/Question8_4.java @@ -0,0 +1,14 @@ + +public class Question8_4 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int total = 0; + total = sum(1, 2); + System.out.println(total); + } + + public static int sum(int x, int y) { + return x + y; + } +} diff --git a/Question08-Method/src/main/java/Question8_5.java b/Question08-Method/src/main/java/Question8_5.java new file mode 100644 index 0000000..93ae497 --- /dev/null +++ b/Question08-Method/src/main/java/Question8_5.java @@ -0,0 +1,27 @@ +import java.util.Scanner; + +public class Question8_5 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + System.out.println("1つ目の数値を入力してください"); + Scanner sc = new Scanner(System.in); + int num1; + num1 = sc.nextInt(); + System.out.println(num1); + + System.out.println("2つ目の数値を入力してください"); + int num2; + num2 = sc.nextInt(); + System.out.println(num2); + + int total = 0; + total = sum(num1, num2); + System.out.println(total); + } + + public static int sum(int num1, int num2) { + return num1 + num2; + } + +} diff --git a/Question08-Method/src/main/java/Question8_6.java b/Question08-Method/src/main/java/Question8_6.java new file mode 100644 index 0000000..f77997a --- /dev/null +++ b/Question08-Method/src/main/java/Question8_6.java @@ -0,0 +1,17 @@ +import java.util.Arrays; + +public class Question8_6 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int[] array = addArray(10, 20); + System.out.println(Arrays.toString(array)); + } + + public static int[] addArray(int x, int y) { + int[] array = new int[2]; + array[0] = x; + array[1] = y; + return array; + } +} diff --git a/Question08-Method/src/main/java/Question8_7.java b/Question08-Method/src/main/java/Question8_7.java new file mode 100644 index 0000000..af5e5d0 --- /dev/null +++ b/Question08-Method/src/main/java/Question8_7.java @@ -0,0 +1,27 @@ + +public class Question8_7 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + printValue("こんにちは"); + printValue("100"); + printValue("10.1"); + printValue("A"); + } + + public static void printValue(String str) { + System.out.println("引数は" + str + "です"); + } + + public static void printValue(int i) { + System.out.println("引数は" + i + "です"); + } + + public static void printValue(float f) { + System.out.println("引数は" + f + "です"); + } + + public static void printValue(char ch) { + System.out.println("引数は" + ch + "です"); + } +} diff --git a/Question08-Method/src/main/java/Question8_8.java b/Question08-Method/src/main/java/Question8_8.java new file mode 100644 index 0000000..fdcc96f --- /dev/null +++ b/Question08-Method/src/main/java/Question8_8.java @@ -0,0 +1,25 @@ + +public class Question8_8 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int total = 0; + total = sum(1, 2); + System.out.println(total); + + total = sum(1, 2, 3); + System.out.println(total); + + total = sum(1, 2, 3, 4); + System.out.println(total); + + } + + public static int sum(int... numbers) { + int total = 0; + for(int n : numbers) { + total += n; + } + return total; + } +} diff --git a/Question09-Package/.classpath b/Question09-Package/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question09-Package/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question09-Package/.gitignore b/Question09-Package/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question09-Package/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question09-Package/.project b/Question09-Package/.project new file mode 100644 index 0000000..b0520c2 --- /dev/null +++ b/Question09-Package/.project @@ -0,0 +1,23 @@ + + + Question09-Package + + + + + + 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/Question09-Package/.settings/org.eclipse.jdt.core.prefs b/Question09-Package/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question09-Package/.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/Question09-Package/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question09-Package/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question09-Package/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question09-Package/src/main/java/Question9_1.java b/Question09-Package/src/main/java/Question9_1.java new file mode 100644 index 0000000..11c7e37 --- /dev/null +++ b/Question09-Package/src/main/java/Question9_1.java @@ -0,0 +1,9 @@ + +public class Question9_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Util.hello(); + } + +} diff --git a/Question09-Package/src/main/java/Question9_2.java b/Question09-Package/src/main/java/Question9_2.java new file mode 100644 index 0000000..aebbe49 --- /dev/null +++ b/Question09-Package/src/main/java/Question9_2.java @@ -0,0 +1,9 @@ + +public class Question9_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + common.Util.showSum(1, 2); + } + +} diff --git a/Question09-Package/src/main/java/Question9_3.java b/Question09-Package/src/main/java/Question9_3.java new file mode 100644 index 0000000..854cb56 --- /dev/null +++ b/Question09-Package/src/main/java/Question9_3.java @@ -0,0 +1,9 @@ +import common.Util; +public class Question9_3 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Util.showSum(1, 2); + } + +} diff --git a/Question09-Package/src/main/java/Util.java b/Question09-Package/src/main/java/Util.java new file mode 100644 index 0000000..5e4f760 --- /dev/null +++ b/Question09-Package/src/main/java/Util.java @@ -0,0 +1,6 @@ + +public class Util { + public static void hello() { + System.out.println("こんにちは"); + } +} diff --git a/Question09-Package/src/main/java/common/Util.java b/Question09-Package/src/main/java/common/Util.java new file mode 100644 index 0000000..c76382e --- /dev/null +++ b/Question09-Package/src/main/java/common/Util.java @@ -0,0 +1,7 @@ +package common; + +public class Util { + public static void showSum(int num1, int num2) { + System.out.println(num1 + num2); + } +} diff --git a/Question10-InstanceAndClass/.classpath b/Question10-InstanceAndClass/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question10-InstanceAndClass/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question10-InstanceAndClass/.gitignore b/Question10-InstanceAndClass/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question10-InstanceAndClass/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question10-InstanceAndClass/.project b/Question10-InstanceAndClass/.project new file mode 100644 index 0000000..781c997 --- /dev/null +++ b/Question10-InstanceAndClass/.project @@ -0,0 +1,23 @@ + + + Question10-InstanceAndClass + + + + + + 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/Question10-InstanceAndClass/.settings/org.eclipse.jdt.core.prefs b/Question10-InstanceAndClass/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question10-InstanceAndClass/.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/Question10-InstanceAndClass/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question10-InstanceAndClass/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question10-InstanceAndClass/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question10-InstanceAndClass/src/main/java/Calculation.java b/Question10-InstanceAndClass/src/main/java/Calculation.java new file mode 100644 index 0000000..0ffc53a --- /dev/null +++ b/Question10-InstanceAndClass/src/main/java/Calculation.java @@ -0,0 +1,9 @@ + +public class Calculation { + int baseNum; + + + public void add(int num) { + this.baseNum += num; + } +} diff --git a/Question10-InstanceAndClass/src/main/java/Car.java b/Question10-InstanceAndClass/src/main/java/Car.java new file mode 100644 index 0000000..7b7da66 --- /dev/null +++ b/Question10-InstanceAndClass/src/main/java/Car.java @@ -0,0 +1,17 @@ +import java.util.Random; + +public class Car { + String color; + int gasoline; + + public int run() { + this.gasoline -= 1; + if(this.gasoline >= 0) { + Random rand = new Random(); + int num = rand.nextInt(15) + 1; + return num; + }else { + return -1; + } + } +} diff --git a/Question10-InstanceAndClass/src/main/java/Question10_1.java b/Question10-InstanceAndClass/src/main/java/Question10_1.java new file mode 100644 index 0000000..988a4ec --- /dev/null +++ b/Question10-InstanceAndClass/src/main/java/Question10_1.java @@ -0,0 +1,15 @@ + +public class Question10_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + User user = new User(); + + user.id = 1000; + user.name = "山田太郎"; + + System.out.println(user.id); + System.out.println(user.name); + } + +} diff --git a/Question10-InstanceAndClass/src/main/java/Question10_2.java b/Question10-InstanceAndClass/src/main/java/Question10_2.java new file mode 100644 index 0000000..0b869da --- /dev/null +++ b/Question10-InstanceAndClass/src/main/java/Question10_2.java @@ -0,0 +1,14 @@ + +public class Question10_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + User user = new User(); + + user.id = 2000; + user.name = "佐藤二郎"; + + user.printProfile(); + } + +} diff --git a/Question10-InstanceAndClass/src/main/java/Question10_3.java b/Question10-InstanceAndClass/src/main/java/Question10_3.java new file mode 100644 index 0000000..c865e4c --- /dev/null +++ b/Question10-InstanceAndClass/src/main/java/Question10_3.java @@ -0,0 +1,19 @@ + +public class Question10_3 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Student student = new Student(); + + student.studentId = 10; + student.name = "田中二郎"; + student.mail = "test@mail.com"; + student.password = "pass"; + + System.out.println(student.studentId); + System.out.println(student.name); + System.out.println(student.mail); + System.out.println(student.password ); + } + +} diff --git a/Question10-InstanceAndClass/src/main/java/Question10_4.java b/Question10-InstanceAndClass/src/main/java/Question10_4.java new file mode 100644 index 0000000..a1a956a --- /dev/null +++ b/Question10-InstanceAndClass/src/main/java/Question10_4.java @@ -0,0 +1,16 @@ + +public class Question10_4 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Calculation cal = new Calculation(); + + cal.baseNum = 100; + + cal.add(100); + + System.out.println(cal.baseNum); + + } + +} diff --git a/Question10-InstanceAndClass/src/main/java/Question10_5.java b/Question10-InstanceAndClass/src/main/java/Question10_5.java new file mode 100644 index 0000000..0f52838 --- /dev/null +++ b/Question10-InstanceAndClass/src/main/java/Question10_5.java @@ -0,0 +1,17 @@ + +public class Question10_5 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Car car = new Car(); + + car.color ="赤"; + car.gasoline = 50; + + int y =car.run(); + + System.out.println(car.color + "色の車は" + y + "進みました"); + System.out.println(car.gasoline); + } + +} diff --git a/Question10-InstanceAndClass/src/main/java/Question10_6.java b/Question10-InstanceAndClass/src/main/java/Question10_6.java new file mode 100644 index 0000000..7ba63fe --- /dev/null +++ b/Question10-InstanceAndClass/src/main/java/Question10_6.java @@ -0,0 +1,29 @@ + +public class Question10_6 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Car car = new Car(); + + car.color = "赤"; + car.gasoline = 50; + int goal = 300; + int totaldistance = 0; + int time = 0; + + while(totaldistance < goal) { + int y = car.run(); + if(y == -1) { + System.out.println(car.color + "色の車は目的地に到達できませんでした"); + break; + }else{ + totaldistance += y; + time += 1; + continue; + } + } + System.out.println(car.color + "色の車は目的地にまで" + time + "時間かかりました。" + + "残りのガソリンは、" + car.gasoline + "リットルです"); + + } +} diff --git a/Question10-InstanceAndClass/src/main/java/Question10_7.java b/Question10-InstanceAndClass/src/main/java/Question10_7.java new file mode 100644 index 0000000..5fda866 --- /dev/null +++ b/Question10-InstanceAndClass/src/main/java/Question10_7.java @@ -0,0 +1,27 @@ + +public class Question10_7 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + User[] userList = new User[3]; + User user1 = new User(); + User user2 = new User(); + User user3 = new User(); + + user1.id = 1; + user1.name = "一郎"; + user2.id = 2; + user2.name = "二郎"; + user3.id = 3; + user3.name = "三郎"; + + userList[0] = user1; + userList[1] = user2; + userList[2] = user3; + + for(int i = 0; i < 3; i++) { + userList[i].printProfile(); + } + } + +} diff --git a/Question10-InstanceAndClass/src/main/java/Question10_8.java b/Question10-InstanceAndClass/src/main/java/Question10_8.java new file mode 100644 index 0000000..5408ab0 --- /dev/null +++ b/Question10-InstanceAndClass/src/main/java/Question10_8.java @@ -0,0 +1,49 @@ + +public class Question10_8 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Car car1 = new Car(); + car1.color = "赤"; + car1.gasoline = 50; + Car car2 = new Car(); + car2.color = "青"; + car2.gasoline = 60; + Car car3 = new Car(); + car3.color = "黄"; + car3.gasoline = 70; + + Car[] cars = new Car[3]; + cars[0] = car1; + cars[1] = car2; + cars[2] = car3; + + int goal = 300; + + for(int i = 0; i < 3; i++) { + int totaldistance = 0; + int time = 0; + int y = 0; + + while(totaldistance < goal) { + y = cars[i].run(); + if(y == -1) { + + break; + }else { + totaldistance += y; + time += 1; + continue; + } + } + if(y == -1) { + System.out.println(cars[i].color + "色の車は、目的地に到達できませんでした"); + }else { + System.out.println(cars[i].color + "色の車は、目的地にまで" + time + "時間かかりました。" + + "残りのガソリンは、" + cars[i].gasoline + "リットルです"); + } + } + + } + +} diff --git a/Question10-InstanceAndClass/src/main/java/Student.java b/Question10-InstanceAndClass/src/main/java/Student.java new file mode 100644 index 0000000..2485d6c --- /dev/null +++ b/Question10-InstanceAndClass/src/main/java/Student.java @@ -0,0 +1,7 @@ + +public class Student { + int studentId; + String name; + String mail; + String password; +} diff --git a/Question10-InstanceAndClass/src/main/java/User.java b/Question10-InstanceAndClass/src/main/java/User.java new file mode 100644 index 0000000..6934b9c --- /dev/null +++ b/Question10-InstanceAndClass/src/main/java/User.java @@ -0,0 +1,10 @@ + +public class User { + int id; + String name; + + + public void printProfile() { + System.out.println("ID" + this.id + ":" + this.name); + } +} diff --git a/Question11-ConstructorAndStatic/.classpath b/Question11-ConstructorAndStatic/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question11-ConstructorAndStatic/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question11-ConstructorAndStatic/.gitignore b/Question11-ConstructorAndStatic/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question11-ConstructorAndStatic/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question11-ConstructorAndStatic/.project b/Question11-ConstructorAndStatic/.project new file mode 100644 index 0000000..ba1d001 --- /dev/null +++ b/Question11-ConstructorAndStatic/.project @@ -0,0 +1,23 @@ + + + Question11-ConstructorAndStatic + + + + + + 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/Question11-ConstructorAndStatic/.settings/org.eclipse.jdt.core.prefs b/Question11-ConstructorAndStatic/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question11-ConstructorAndStatic/.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/Question11-ConstructorAndStatic/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question11-ConstructorAndStatic/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question11-ConstructorAndStatic/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question11-ConstructorAndStatic/src/main/java/Atm.java b/Question11-ConstructorAndStatic/src/main/java/Atm.java new file mode 100644 index 0000000..3132da9 --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Atm.java @@ -0,0 +1,14 @@ + +public class Atm { + int credit = 100000; + + public void withdraw(Wallet wallet, int money) { + if(credit < money) { + System.out.println("預金残高不足です。現金の引き出しに失敗しました。"); + }else { + credit -= money; + wallet.money += money; + System.out.println("ATMの残り残高は" + credit + "です"); + } + } +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Cat.java b/Question11-ConstructorAndStatic/src/main/java/Cat.java new file mode 100644 index 0000000..966ccce --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Cat.java @@ -0,0 +1,14 @@ + +public class Cat { + String name; + + //ⅰ + Cat(){ + this.name = "タマ"; + } + + //ⅱ + public Cat(String name) { + this.name = name; + } +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Jam.java b/Question11-ConstructorAndStatic/src/main/java/Jam.java new file mode 100644 index 0000000..e8c5fec --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Jam.java @@ -0,0 +1,8 @@ + +public class Jam { + String material; + + public Jam(String material) { + this.material = material; + } +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Question11_1.java b/Question11-ConstructorAndStatic/src/main/java/Question11_1.java new file mode 100644 index 0000000..4ff2ac3 --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Question11_1.java @@ -0,0 +1,19 @@ + +public class Question11_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Wallet wallet = new Wallet(); + User user = new User(); + + + wallet.money = 10000; + user.name = "太郎"; + user.wallet = wallet; + + user.confirmWallet(); + user.useMoney(1000); + user.confirmWallet(); + } + +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Question11_2.java b/Question11-ConstructorAndStatic/src/main/java/Question11_2.java new file mode 100644 index 0000000..5f9e711 --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Question11_2.java @@ -0,0 +1,17 @@ + +public class Question11_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Wallet wallet = new Wallet(); + Atm atm = new Atm(); + + wallet.money = 10000; + atm.withdraw(wallet, 100000); + System.out.println(wallet.money); + + atm.withdraw(wallet, 100000); + System.out.println(wallet.money); + } + +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Question11_3.java b/Question11-ConstructorAndStatic/src/main/java/Question11_3.java new file mode 100644 index 0000000..687c17c --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Question11_3.java @@ -0,0 +1,13 @@ + +public class Question11_3 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Cat cat1 = new Cat(); + Cat cat2 = new Cat("ミケ"); + + System.out.println(cat1.name); + System.out.println(cat2.name); + } + +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Question11_4.java b/Question11-ConstructorAndStatic/src/main/java/Question11_4.java new file mode 100644 index 0000000..e57089b --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Question11_4.java @@ -0,0 +1,15 @@ + +public class Question11_4 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Student student = new Student(); + student.name = "太郎"; + Student.group= "A"; + Student.teacher = "山田"; + + student.studentProfile(); + Student.groupProfile(); + } + +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Question11_5.java b/Question11-ConstructorAndStatic/src/main/java/Question11_5.java new file mode 100644 index 0000000..1de6fa1 --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Question11_5.java @@ -0,0 +1,12 @@ + +public class Question11_5 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Jam jam = new Jam("ブルーベリー"); + Toast toast = new Toast(jam); + + toast.taste(); + } + +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Student.java b/Question11-ConstructorAndStatic/src/main/java/Student.java new file mode 100644 index 0000000..b69435b --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Student.java @@ -0,0 +1,14 @@ + +public class Student { + String name; + static String group; + static String teacher; + + public void studentProfile() { + System.out.println(this.name + "は" + group + "教室の生徒です。"); + } + + public static void groupProfile() { + System.out.println(group + "教室の担任は" + teacher + "先生です。"); + } +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Toast.java b/Question11-ConstructorAndStatic/src/main/java/Toast.java new file mode 100644 index 0000000..4c41a31 --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Toast.java @@ -0,0 +1,12 @@ + +public class Toast { + Jam jam; + + public Toast(Jam jam) { + this.jam = jam; + } + + public void taste() { + System.out.println(this.jam.material + "味のトーストです。"); + } +} diff --git a/Question11-ConstructorAndStatic/src/main/java/User.java b/Question11-ConstructorAndStatic/src/main/java/User.java new file mode 100644 index 0000000..e919baf --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/User.java @@ -0,0 +1,16 @@ + +public class User { + String name; + Wallet wallet; + + public void useMoney(int money) { + this.wallet.money -= money; + System.out.println(this.name + "は財布の中のお金を" + + money + "円使用しました"); + } + + public void confirmWallet() { + System.out.println(this.name + "の財布の中の残額は" + + this.wallet.money + "円です"); + } +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Wallet.java b/Question11-ConstructorAndStatic/src/main/java/Wallet.java new file mode 100644 index 0000000..b54b096 --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Wallet.java @@ -0,0 +1,4 @@ + +public class Wallet { + int money; +} diff --git a/Question12-Encapsulation/.classpath b/Question12-Encapsulation/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question12-Encapsulation/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question12-Encapsulation/.gitignore b/Question12-Encapsulation/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question12-Encapsulation/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question12-Encapsulation/.project b/Question12-Encapsulation/.project new file mode 100644 index 0000000..5aa0f8a --- /dev/null +++ b/Question12-Encapsulation/.project @@ -0,0 +1,23 @@ + + + Question12-Encapsulation + + + + + + 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/Question12-Encapsulation/.settings/org.eclipse.jdt.core.prefs b/Question12-Encapsulation/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question12-Encapsulation/.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/Question12-Encapsulation/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question12-Encapsulation/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question12-Encapsulation/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question12-Encapsulation/src/main/java/Item.java b/Question12-Encapsulation/src/main/java/Item.java new file mode 100644 index 0000000..c762bb9 --- /dev/null +++ b/Question12-Encapsulation/src/main/java/Item.java @@ -0,0 +1,8 @@ + +public class Item { + public String name = "アイテムA"; + + public String getName() { + return name; + } +} diff --git a/Question12-Encapsulation/src/main/java/Question12_1.java b/Question12-Encapsulation/src/main/java/Question12_1.java new file mode 100644 index 0000000..b8718c7 --- /dev/null +++ b/Question12-Encapsulation/src/main/java/Question12_1.java @@ -0,0 +1,18 @@ + +public class Question12_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + User user = new User(); + user.setId(1000); + user.setName("リゾーム太郎"); + user.setAddress("rhizome@hogehoge.com"); + user.setPass("12345"); + + System.out.println("ID :" + user.getId()); + System.out.println("名前 :" + user.getName()); + System.out.println("メールアドレス  :" + user.getAddress()); + System.out.println("パスワード  :" + user.getPass()); + } + +} diff --git a/Question12-Encapsulation/src/main/java/Question12_2.java b/Question12-Encapsulation/src/main/java/Question12_2.java new file mode 100644 index 0000000..ce0c204 --- /dev/null +++ b/Question12-Encapsulation/src/main/java/Question12_2.java @@ -0,0 +1,10 @@ + +public class Question12_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Item item = new Item(); + System.out.println(item.getName()); + } + +} diff --git a/Question12-Encapsulation/src/main/java/User.java b/Question12-Encapsulation/src/main/java/User.java new file mode 100644 index 0000000..f3e5ede --- /dev/null +++ b/Question12-Encapsulation/src/main/java/User.java @@ -0,0 +1,33 @@ + +public class User { + public int id; + public String name; + public String address; + public String pass; + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getAddress() { + return address; + } + public void setAddress(String address) { + this.address = address; + } + public String getPass() { + return pass; + } + public void setPass(String pass) { + this.pass = pass; + } + + +} diff --git a/Question13-Extends/.classpath b/Question13-Extends/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question13-Extends/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question13-Extends/.gitignore b/Question13-Extends/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question13-Extends/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question13-Extends/.project b/Question13-Extends/.project new file mode 100644 index 0000000..5c757c4 --- /dev/null +++ b/Question13-Extends/.project @@ -0,0 +1,23 @@ + + + Question13-Extends + + + + + + 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/Question13-Extends/.settings/org.eclipse.jdt.core.prefs b/Question13-Extends/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question13-Extends/.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/Question13-Extends/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question13-Extends/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question13-Extends/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question13-Extends/src/main/java/Animal.java b/Question13-Extends/src/main/java/Animal.java new file mode 100644 index 0000000..fe1528e --- /dev/null +++ b/Question13-Extends/src/main/java/Animal.java @@ -0,0 +1,22 @@ + +public class Animal { + private String name; + + public void run() { + System.out.println(this.name + "は走りました。"); + } + + public void eat() { + System.out.println(this.name + "は食事をしました。"); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + +} diff --git a/Question13-Extends/src/main/java/Cat.java b/Question13-Extends/src/main/java/Cat.java new file mode 100644 index 0000000..9c5ceef --- /dev/null +++ b/Question13-Extends/src/main/java/Cat.java @@ -0,0 +1,4 @@ + +public class Cat extends Animal{ + +} diff --git a/Question13-Extends/src/main/java/Character.java b/Question13-Extends/src/main/java/Character.java new file mode 100644 index 0000000..02878dc --- /dev/null +++ b/Question13-Extends/src/main/java/Character.java @@ -0,0 +1,53 @@ + +public class Character { + private String name; + private int hp; + private int power; + private int defense; + + public Character(int hp, int power, int defense) { + this.hp = hp; + this.power = power; + this.defense = defense; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int attack() { + return this.power; + } + + public boolean damage(int enemyAttack) { + int damage = enemyAttack - this.defense; //ダメージ量の計算 + if(damage <= 0) { + damage = 1; //計算結果が0以下ならダメージ量1にする + } + + this.hp -= damage; //hpからダメージ量引いて残りをhpにする + boolean dead= false; //戦闘不能かどうかを真偽地を使って判断 + + if(this.hp <= 0) { //hpが0以下なら + this.hp = 0; //hpを0に補正 + dead = true; + } + + System.out.println(this.name + "は" + damage + "のダメージを受けた"); + System.out.println(this.name + "の残りの体力は" + this.hp + "。"); + + if(dead) { //戦闘不能の時 + System.out.println(this.name + "はちからつきた。"); + } + return dead; + } + + public String Parameters() { //パラメーターを文字列で返す + return "名前:" + this.name + "\n" + "体力:" + this.hp + "\n" + + "力" + this.power + "\n" + "耐久" + this.defense; + } +} diff --git a/Question13-Extends/src/main/java/Dog.java b/Question13-Extends/src/main/java/Dog.java new file mode 100644 index 0000000..b4a8a11 --- /dev/null +++ b/Question13-Extends/src/main/java/Dog.java @@ -0,0 +1,6 @@ + +public class Dog extends Animal{ + public void eat() { + System.out.println(getName() + "はドッグフードを食べました。"); + } +} diff --git a/Question13-Extends/src/main/java/Hero.java b/Question13-Extends/src/main/java/Hero.java new file mode 100644 index 0000000..8107237 --- /dev/null +++ b/Question13-Extends/src/main/java/Hero.java @@ -0,0 +1,6 @@ + +public class Hero extends Character{ + public Hero(){ + super(25, 10, 7); + } +} diff --git a/Question13-Extends/src/main/java/Item.java b/Question13-Extends/src/main/java/Item.java new file mode 100644 index 0000000..382eedd --- /dev/null +++ b/Question13-Extends/src/main/java/Item.java @@ -0,0 +1,28 @@ + +public class Item { + private String eName; + private int addDamage; + + public Item(String eNmae, int addDamage) { + this.eName = eNmae; + this.addDamage = addDamage; + + + } + + public String geteNmae() { + return eName; + } + + public void seteNmae(String eNmae) { + this.eName = eNmae; + } + + public int getAddDamage() { + return addDamage; + } + + public void setAddDamage(int addDamage) { + this.addDamage = addDamage; + } +} diff --git a/Question13-Extends/src/main/java/Question13_1.java b/Question13-Extends/src/main/java/Question13_1.java new file mode 100644 index 0000000..9d4c981 --- /dev/null +++ b/Question13-Extends/src/main/java/Question13_1.java @@ -0,0 +1,12 @@ + +public class Question13_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Cat cat = new Cat(); + cat.setName("タマ"); + cat.run(); + cat.eat(); + } + +} diff --git a/Question13-Extends/src/main/java/Question13_2.java b/Question13-Extends/src/main/java/Question13_2.java new file mode 100644 index 0000000..3d881aa --- /dev/null +++ b/Question13-Extends/src/main/java/Question13_2.java @@ -0,0 +1,12 @@ + +public class Question13_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Dog dog = new Dog(); + dog.setName("ポチ"); + dog.run(); + dog.eat(); + } + +} diff --git a/Question13-Extends/src/main/java/Question13_3.java b/Question13-Extends/src/main/java/Question13_3.java new file mode 100644 index 0000000..3094d9f --- /dev/null +++ b/Question13-Extends/src/main/java/Question13_3.java @@ -0,0 +1,9 @@ + +public class Question13_3 { + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Hero hero = new Hero(); + hero.setName("勇者"); + System.out.println(hero.Parameters()); + } +} diff --git a/Question13-Extends/src/main/java/Question13_4.java b/Question13-Extends/src/main/java/Question13_4.java new file mode 100644 index 0000000..c7e37ac --- /dev/null +++ b/Question13-Extends/src/main/java/Question13_4.java @@ -0,0 +1,11 @@ + +public class Question13_4 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Slime slime = new Slime(); + slime.setName("スライム"); + System.out.println(slime.Parameters()); + } + +} diff --git a/Question13-Extends/src/main/java/Question13_5.java b/Question13-Extends/src/main/java/Question13_5.java new file mode 100644 index 0000000..43671ff --- /dev/null +++ b/Question13-Extends/src/main/java/Question13_5.java @@ -0,0 +1,26 @@ + +public class Question13_5 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Hero hero = new Hero(); + hero.setName("勇者"); + Slime slime = new Slime(); + slime.setName("スライム"); + + while(true) { + //勇者の攻撃 + boolean slimedead = slime.damage(10); //スライムがダメージを受ける + //スライムの戦闘不能判断 + if(slimedead == true) { + System.out.println("勇者はスライムとの戦闘に勝利した"); + break; + } + boolean herodead = hero.damage(5); + if(herodead == true) { + System.out.println("勇者はスライムとの戦闘に敗北した"); + break; + } + } + } +} diff --git a/Question13-Extends/src/main/java/Question13_6.java b/Question13-Extends/src/main/java/Question13_6.java new file mode 100644 index 0000000..0171c69 --- /dev/null +++ b/Question13-Extends/src/main/java/Question13_6.java @@ -0,0 +1,19 @@ + +public class Question13_6 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + SuperHero sHero = new SuperHero(); + sHero.setName("勇者(装備あり)"); + + Slime slime = new Slime(); + + Item item = new Item("こんぼう", 5); + + sHero.setItem(item); + int damage = sHero.attack(); + + System.out.println(damage); + } + +} diff --git a/Question13-Extends/src/main/java/Question13_7.java b/Question13-Extends/src/main/java/Question13_7.java new file mode 100644 index 0000000..d737cc3 --- /dev/null +++ b/Question13-Extends/src/main/java/Question13_7.java @@ -0,0 +1,32 @@ + +public class Question13_7 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + SuperHero sHero = new SuperHero(); + sHero.setName("勇者(装備あり)"); + + Slime slime = new Slime(); + slime.setName("スライム"); + + Item item = new Item("ロングソード", 20); + sHero.setItem(item); + int da = sHero.attack(); + + while(true) { + boolean slimedead = slime.damage(da); + if(slimedead == true) { + System.out.println(sHero.getName() + "は" + slime.getName() + + "との戦闘に勝利した"); + break; + } + boolean sHerodead = sHero.damage(5); + if(sHerodead == true) { + System.out.println(slime.getName() + "は" + sHero.getName() + + "との戦闘に勝利した"); + break; + } + } + } + +} diff --git a/Question13-Extends/src/main/java/Slime.java b/Question13-Extends/src/main/java/Slime.java new file mode 100644 index 0000000..d2c7fea --- /dev/null +++ b/Question13-Extends/src/main/java/Slime.java @@ -0,0 +1,6 @@ + +public class Slime extends Character{ + public Slime(){ + super(10, 5, 2); + } +} diff --git a/Question13-Extends/src/main/java/SuperHero.java b/Question13-Extends/src/main/java/SuperHero.java new file mode 100644 index 0000000..89ad2b7 --- /dev/null +++ b/Question13-Extends/src/main/java/SuperHero.java @@ -0,0 +1,20 @@ + +public class SuperHero extends Hero{ + public SuperHero() { + super(); + } + + private Item item; + + public Item getItem() { + return item; + } + + public void setItem(Item item) { + this.item = item; + } + + public int attack() { + return super.attack() + item.getAddDamage(); + } +} diff --git a/Question14-Interface/.classpath b/Question14-Interface/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question14-Interface/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question14-Interface/.gitignore b/Question14-Interface/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question14-Interface/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question14-Interface/.project b/Question14-Interface/.project new file mode 100644 index 0000000..e86df9d --- /dev/null +++ b/Question14-Interface/.project @@ -0,0 +1,23 @@ + + + Question14-Interface + + + + + + 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/Question14-Interface/.settings/org.eclipse.jdt.core.prefs b/Question14-Interface/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question14-Interface/.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/Question14-Interface/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question14-Interface/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question14-Interface/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question14-Interface/src/main/java/Book.java b/Question14-Interface/src/main/java/Book.java new file mode 100644 index 0000000..cf85dd2 --- /dev/null +++ b/Question14-Interface/src/main/java/Book.java @@ -0,0 +1,6 @@ +import java.util.List; + +public interface Book { + String title(); + List chapter(); +} diff --git a/Question14-Interface/src/main/java/Book1_programming.java b/Question14-Interface/src/main/java/Book1_programming.java new file mode 100644 index 0000000..21433d9 --- /dev/null +++ b/Question14-Interface/src/main/java/Book1_programming.java @@ -0,0 +1,21 @@ +import java.util.ArrayList; +import java.util.List; + +public class Book1_programming implements Book{ + public String title() { + return "プログラミング基礎入門"; + } + + + public List chapter(){ + List chapter = new ArrayList(); + chapter.add("式と変数"); + chapter.add("制御構文"); + chapter.add("メソッド"); + chapter.add("オブジェクト指向"); + chapter.add("継承"); + return chapter; + } + + +} diff --git a/Question14-Interface/src/main/java/Car.java b/Question14-Interface/src/main/java/Car.java new file mode 100644 index 0000000..d5ce7d7 --- /dev/null +++ b/Question14-Interface/src/main/java/Car.java @@ -0,0 +1,5 @@ + +public interface Car { + void refill(int amount); + void run(int speed); +} diff --git a/Question14-Interface/src/main/java/Question14_1.java b/Question14-Interface/src/main/java/Question14_1.java new file mode 100644 index 0000000..4afbdfc --- /dev/null +++ b/Question14-Interface/src/main/java/Question14_1.java @@ -0,0 +1,11 @@ + +public class Question14_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Book1_programming book = new Book1_programming(); + System.out.println(book.title()); + System.out.println(book.chapter()); + } + +} diff --git a/Question14-Interface/src/main/java/Question14_2.java b/Question14-Interface/src/main/java/Question14_2.java new file mode 100644 index 0000000..4cc21d2 --- /dev/null +++ b/Question14-Interface/src/main/java/Question14_2.java @@ -0,0 +1,11 @@ + +public class Question14_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + sportCar car = new sportCar(); + car.refill(100); + car.run(100); + car.run(301); + } +} diff --git a/Question14-Interface/src/main/java/sportCar.java b/Question14-Interface/src/main/java/sportCar.java new file mode 100644 index 0000000..2c023a8 --- /dev/null +++ b/Question14-Interface/src/main/java/sportCar.java @@ -0,0 +1,14 @@ + +public class sportCar implements Car{ + public void refill(int num) { + System.out.println("ハイオクを" + num + "リットル補充した"); + } + + public void run(int speed) { + if(speed > 300) { + System.out.println("速度オーバーです"); + }else { + System.out.println("スポーツカーは時速" + speed + "キロで走った"); + } + } +} 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..a05b1e2 --- /dev/null +++ b/Question15-Polymorphism/.project @@ -0,0 +1,23 @@ + + + Question15-Polymorphism + + + + + + 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/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..03aa14d --- /dev/null +++ b/Question15-Polymorphism/src/main/java/Car.java @@ -0,0 +1,14 @@ + +public class Car { + String name; + int speed; + + public Car(String name, int speed) { + this.name = name; + this.speed = speed; + } + + public String drive() { + return this.name + "は時速" + this.speed + "で走った"; + } +} diff --git a/Question15-Polymorphism/src/main/java/Question15_1.java b/Question15-Polymorphism/src/main/java/Question15_1.java new file mode 100644 index 0000000..d2bef6b --- /dev/null +++ b/Question15-Polymorphism/src/main/java/Question15_1.java @@ -0,0 +1,13 @@ + +public class Question15_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Car car1 = new SportsCar(); + System.out.println(car1.drive()); + + Car car2 = new Truck(); + System.out.println(car2.drive()); + } + +} diff --git a/Question15-Polymorphism/src/main/java/Question15_2.java b/Question15-Polymorphism/src/main/java/Question15_2.java new file mode 100644 index 0000000..68371a0 --- /dev/null +++ b/Question15-Polymorphism/src/main/java/Question15_2.java @@ -0,0 +1,17 @@ + +public class Question15_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Car car1 = new SportsCar(); + Car car2 = new Truck(); + + Car[] cars = new Car[2]; + cars[0] = car1; + cars[1] = car2; + + System.out.println(car1.drive()); + System.out.println(car2.drive()); + } + +} diff --git a/Question15-Polymorphism/src/main/java/Question15_3.java b/Question15-Polymorphism/src/main/java/Question15_3.java new file mode 100644 index 0000000..172a394 --- /dev/null +++ b/Question15-Polymorphism/src/main/java/Question15_3.java @@ -0,0 +1,10 @@ + +public class Question15_3 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + Car car = new SportsCar(); + System.out.println(((SportsCar)car).turbodrive()); + } + +} diff --git a/Question15-Polymorphism/src/main/java/SportsCar.java b/Question15-Polymorphism/src/main/java/SportsCar.java new file mode 100644 index 0000000..c682f39 --- /dev/null +++ b/Question15-Polymorphism/src/main/java/SportsCar.java @@ -0,0 +1,10 @@ + +public class SportsCar extends Car{ + public SportsCar() { + super("スポーツカー", 100); + } + + public String turbodrive() { + return this.name + "は時速" + (this.speed * 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..59b661a --- /dev/null +++ b/Question15-Polymorphism/src/main/java/Truck.java @@ -0,0 +1,8 @@ + +public class Truck extends Car{ + public Truck() { + super("トラック", 30); + } + + +} 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_1.java b/Question16-Exception/src/main/java/Question16_1.java new file mode 100644 index 0000000..e7f0e5a --- /dev/null +++ b/Question16-Exception/src/main/java/Question16_1.java @@ -0,0 +1,19 @@ + +public class Question16_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + try { + int result1 = divide(10, 2); + System.out.println(result1); + int result2 = divide(10, 0); + }catch(ArithmeticException e){ + System.out.println("0で割ることはできません"); + } + } + + public static int divide(int num1, int num2) { + return num1 / num2; + } + +} diff --git a/Question16-Exception/src/main/java/Question16_2.java b/Question16-Exception/src/main/java/Question16_2.java new file mode 100644 index 0000000..5b08c3c --- /dev/null +++ b/Question16-Exception/src/main/java/Question16_2.java @@ -0,0 +1,32 @@ + +public class Question16_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + ExceptionHandling("10"); + ExceptionHandling("abc"); + ExceptionHandling(""); + } + + public static void ExceptionHandling(String scr) { + try { + int result = convertandtwice(scr); + System.out.println(result); + }catch(NumberFormatException e) { + System.out.println("数値に変換できません"); + }catch(IllegalArgumentException e) { + System.out.println("入力が空です"); + } + } + + public static int convertandtwice(String str) { + if(str.isEmpty()) { + throw new IllegalArgumentException(); + } + int num = Integer.parseInt(str); + num *= 2; + return num; + } + + +} diff --git a/Question16-Exception/src/main/java/Question16_3.java b/Question16-Exception/src/main/java/Question16_3.java new file mode 100644 index 0000000..5efa589 --- /dev/null +++ b/Question16-Exception/src/main/java/Question16_3.java @@ -0,0 +1,30 @@ + +public class Question16_3 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + int[] nums = new int[3]; + nums[0] = 10; + nums[1] = 20; + nums[2] = 30; + + Check(nums, 1); + Check(nums, 5); + } + + public static int getArrayValue(int[] num1, int num2 ) { + return num1[num2]; + } + + public static void Check(int[] num1, int num2 ) { + try { + int result = getArrayValue(num1, num2); + System.out.println(result); + }catch(ArrayIndexOutOfBoundsException e) { + System.out.println("指定した位置にデータがありません"); + }finally{ + System.out.println("処理を終了します"); + } + } + +} diff --git a/Question16-Exception/src/main/java/Question16_4.java b/Question16-Exception/src/main/java/Question16_4.java new file mode 100644 index 0000000..b595b32 --- /dev/null +++ b/Question16-Exception/src/main/java/Question16_4.java @@ -0,0 +1,25 @@ + +public class Question16_4 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + + try{ + int num1 = ageCheck(20); + System.out.println("年齢は" + num1 + "です"); + + int num2 = ageCheck(-5); + System.out.println("年齢は" + num2 + "です"); + }catch(testException e) { + System.out.println(e.getMessage()+ "は不正な年齢です"); + } + } + + public static int ageCheck(int num) throws testException { + if(num < 0) { + throw new testException("num"); + } + return num; + } + +} diff --git a/Question16-Exception/src/main/java/testException.java b/Question16-Exception/src/main/java/testException.java new file mode 100644 index 0000000..fc36286 --- /dev/null +++ b/Question16-Exception/src/main/java/testException.java @@ -0,0 +1,6 @@ + +public class testException extends Exception { + public testException(String message) { + super(message); + } +}