1030自主学習

This commit is contained in:
2026-10-30 17:49:49 +09:00
parent d9529e2971
commit c0101fc96d
186 changed files with 2507 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>

View File

@@ -0,0 +1 @@
/build/

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Question11-ConstructorAndStatic</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -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

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="21"/>
</faceted-project>

View File

@@ -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 + "です");
}
}
}

View File

@@ -0,0 +1,14 @@
public class Cat {
String name;
//ⅰ
Cat(){
this.name = "タマ";
}
//ⅱ
public Cat(String name) {
this.name = name;
}
}

View File

@@ -0,0 +1,8 @@
public class Jam {
String material;
public Jam(String material) {
this.material = material;
}
}

View File

@@ -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();
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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 + "先生です。");
}
}

View File

@@ -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 + "味のトーストです。");
}
}

View File

@@ -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 + "円です");
}
}

View File

@@ -0,0 +1,4 @@
public class Wallet {
int money;
}