完了済
This commit is contained in:
20
Question11-ConstructorAndStatic/src/main/java/Atm.java
Normal file
20
Question11-ConstructorAndStatic/src/main/java/Atm.java
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
public class Atm {
|
||||
|
||||
int credit;
|
||||
|
||||
public Atm () {
|
||||
this.credit = 100000;
|
||||
}
|
||||
|
||||
public void withdraw( Wallet wallet , int money ) {
|
||||
if ( this.credit < money ) {
|
||||
System.out.println("預金残高不足です。現金の引き出しに失敗しました。");
|
||||
} else {
|
||||
this.credit = this.credit - money;
|
||||
wallet.money = wallet.money + money;
|
||||
System.out.println("ATMの残り残高は"+this.credit+"です");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
14
Question11-ConstructorAndStatic/src/main/java/Cat.java
Normal file
14
Question11-ConstructorAndStatic/src/main/java/Cat.java
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
public class Cat {
|
||||
|
||||
String name;
|
||||
|
||||
public Cat() {
|
||||
this.name = "タマ";
|
||||
}
|
||||
|
||||
public Cat( String name ) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
10
Question11-ConstructorAndStatic/src/main/java/Jam.java
Normal file
10
Question11-ConstructorAndStatic/src/main/java/Jam.java
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
public class Jam {
|
||||
|
||||
String material;
|
||||
|
||||
public Jam( String jam ) {
|
||||
this.material = jam;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
public class Question11_1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
Wallet wallet = new Wallet();
|
||||
wallet.money = 10000;
|
||||
|
||||
User user = new User();
|
||||
user.name = "太郎";
|
||||
user.wallet = wallet;
|
||||
|
||||
user.confirmWallet();
|
||||
user.useMoney(1000);
|
||||
user.confirmWallet();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
public class Question11_2 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
Wallet wallet = new Wallet();
|
||||
wallet.money = 10000;
|
||||
|
||||
Atm atm = new Atm();
|
||||
|
||||
atm.withdraw(wallet,100000);
|
||||
System.out.println(wallet.money);
|
||||
|
||||
atm.withdraw(wallet,100000);
|
||||
System.out.println(wallet.money);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
public class Question11_3 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
Cat cat1 = new Cat();
|
||||
System.out.println(cat1.name);
|
||||
|
||||
Cat cat2 = new Cat("ミケ");
|
||||
System.out.println(cat2.name);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
public class Question11_5 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
Jam jam = new Jam("ブルーベリー");
|
||||
Toast toast = new Toast(jam);
|
||||
|
||||
toast.taste();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
16
Question11-ConstructorAndStatic/src/main/java/Student.java
Normal file
16
Question11-ConstructorAndStatic/src/main/java/Student.java
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
public class Student {
|
||||
|
||||
String name;
|
||||
static String group;
|
||||
static String teacher;
|
||||
|
||||
public void studentProfile() {
|
||||
System.out.println(this.name+"は"+this.group+"教室の生徒です。");
|
||||
}
|
||||
|
||||
public void groupProfile() {
|
||||
System.out.println(this.group+"教室の担任は"+this.teacher+"先生です。");
|
||||
}
|
||||
|
||||
}
|
||||
14
Question11-ConstructorAndStatic/src/main/java/Toast.java
Normal file
14
Question11-ConstructorAndStatic/src/main/java/Toast.java
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
public class Toast {
|
||||
|
||||
Jam jam;
|
||||
|
||||
public Toast(Jam jam) {
|
||||
this.jam = jam;
|
||||
}
|
||||
|
||||
public void taste() {
|
||||
System.out.println(jam.material+"味のトーストです。");
|
||||
}
|
||||
|
||||
}
|
||||
16
Question11-ConstructorAndStatic/src/main/java/User.java
Normal file
16
Question11-ConstructorAndStatic/src/main/java/User.java
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
public class User {
|
||||
|
||||
String name;
|
||||
Wallet wallet;
|
||||
|
||||
public void useMoney( int money ) {
|
||||
this.wallet.money = this.wallet.money - money;
|
||||
System.out.println(this.name+"は財布の中のお金を"+money+"円使用しました");
|
||||
}
|
||||
|
||||
public void confirmWallet() {
|
||||
System.out.println(this.name+"の財布の中の残額は"+this.wallet.money+"円です");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
public class Wallet {
|
||||
|
||||
int money;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user