20261027
This commit is contained in:
@@ -7,12 +7,13 @@ public class Atm {
|
||||
//withdrawメソッドの生成
|
||||
public void withdraw(Wallet2 wallet,int money) {
|
||||
|
||||
wallet.money = wallet.money + money;
|
||||
|
||||
if(credit < money) {
|
||||
if(this.credit < money) {
|
||||
System.out.println("預金残高不足です。現金の引き出しに失敗しました。");
|
||||
} else {
|
||||
System.out.println("ATMの残り残高はx" + (credit - wallet.money) + "です");
|
||||
this.credit = this.credit - money;
|
||||
wallet.money = wallet.money + money;
|
||||
System.out.println("ATMの残り残高は" + this.credit + "です");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,10 +8,12 @@ public class Question11_02 {
|
||||
|
||||
//wallet の money フィールドに 10000 を代入
|
||||
wallet.money = 10000;
|
||||
|
||||
|
||||
|
||||
//Atm 型の変数 atm を宣言し、Atm のインスタンスを代入
|
||||
Atm atm = new Atm();
|
||||
|
||||
|
||||
//atm の withdraw メソッドを、第一引数に wallet、第二引数に 100000 を渡して呼び出す
|
||||
atm.withdraw(wallet,100000);
|
||||
@@ -19,8 +21,8 @@ public class Question11_02 {
|
||||
//wallet の money フィールドの値を出力
|
||||
System.out.println(wallet.money);
|
||||
|
||||
atm.withdraw(wallet,100000);
|
||||
|
||||
atm.withdraw(wallet,100000);
|
||||
System.out.println(wallet.money);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
public class Question11_04 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
//Student2のインスタンス生成
|
||||
Student2 deta = new Student2();
|
||||
|
||||
//生徒の名前(name フィールド)に 太郎 を設定
|
||||
deta.name = "太郎";
|
||||
Student2.group = "A";
|
||||
Student2.teacher = "山田";
|
||||
|
||||
deta.studentProfile();
|
||||
Student2.groupProfile();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
17
Question11-ConstructorAndStatic/src/main/java/Student2.java
Normal file
17
Question11-ConstructorAndStatic/src/main/java/Student2.java
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
public class Student2 {
|
||||
//Student2クラスで3つのフィールドを宣言する
|
||||
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 +"先生です。");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,4 +2,6 @@
|
||||
public class Wallet2 {
|
||||
//フィールドの宣言
|
||||
int money;
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user