init
This commit is contained in:
29
Question11-ConstructorAndStatic/src/Atm.java
Normal file
29
Question11-ConstructorAndStatic/src/Atm.java
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
|
||||
public class Atm {
|
||||
// 預金残高
|
||||
int credit = 100000;
|
||||
|
||||
/**
|
||||
* 預金を引き出す処理を行う。
|
||||
* 指定した金額を預金残高から減らして、財布の中にお金を追加する
|
||||
* @param wallet 財布
|
||||
* @param money 引き出す金額
|
||||
*/
|
||||
void withdraw(Wallet wallet, int money) {
|
||||
// 引き出す金額が預金残高より大きい場合
|
||||
if (credit < money) {
|
||||
System.out.println("預金残高不足です。現金の引き出しに失敗しました。");
|
||||
// 引き出す金額が預金残高より小さい場合
|
||||
} else {
|
||||
// 預金残高から指定金額を引く
|
||||
credit -= money;
|
||||
// 財布の中のお金に指定金額を追加
|
||||
wallet.money += money;
|
||||
System.out.println("ATMの残り残高は" + this.credit + "です");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
18
Question11-ConstructorAndStatic/src/Cat.java
Normal file
18
Question11-ConstructorAndStatic/src/Cat.java
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
|
||||
public class Cat {
|
||||
String name;
|
||||
|
||||
/*
|
||||
* TODO 以下のコンストラクタを作成してください。
|
||||
* 引数 なし
|
||||
* nameフィールドに タマ を代入する
|
||||
*/
|
||||
|
||||
/*
|
||||
* TODO 以下のコンストラクタを作成してください。
|
||||
* 引数 String name
|
||||
* nameフィールドに 引数に渡された name を代入する
|
||||
*/
|
||||
|
||||
}
|
||||
12
Question11-ConstructorAndStatic/src/Jam.java
Normal file
12
Question11-ConstructorAndStatic/src/Jam.java
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
public class Jam {
|
||||
|
||||
// TODO String型のmaterialフィールドを作成してください。
|
||||
|
||||
/*
|
||||
* TODO String型の引数を1つ持つコンストラクタを作成してください。
|
||||
* 処理:与えられた引数をmaterialフィールドに代入する
|
||||
*/
|
||||
|
||||
}
|
||||
29
Question11-ConstructorAndStatic/src/PTra11_01.java
Normal file
29
Question11-ConstructorAndStatic/src/PTra11_01.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* PTra11_01.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
public class PTra11_01 {
|
||||
public static void main(String[] args) {
|
||||
// ※ この問題はUserクラス、Walletクラスを使用して解いてください。
|
||||
// TODO Wallet型変数 wallet をWallet型のインスタンスで初期化してください。
|
||||
|
||||
// TODO walletのmoneyフィールドに10000を代入してください。
|
||||
|
||||
// TODO User型変数 user をUser型のインスタンスで初期化してください
|
||||
|
||||
// TODO userのnameフィールドに太郎を代入してください。
|
||||
|
||||
// TODO userのwalletフィールドに作成したwalletを代入してください。
|
||||
|
||||
// TODO userのconfirmWalletメソッドを実行してください。
|
||||
// ※ 太郎の財布の中の残額は10000円です と表示されます。
|
||||
|
||||
// TODO userのuseMoneyメソッドを 引数1000 で実行してください。
|
||||
|
||||
// TODO userのconfirmWalletメソッドを再度実行してください。
|
||||
// ※ 太郎の財布の中の残額は9000円です と表示されます。
|
||||
|
||||
}
|
||||
}
|
||||
35
Question11-ConstructorAndStatic/src/PTra11_02.java
Normal file
35
Question11-ConstructorAndStatic/src/PTra11_02.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* PTra11_02.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
public class PTra11_02 {
|
||||
public static void main(String[] args) {
|
||||
// ※ この問題はWalletクラス、Atmクラスを使用して解いてください。
|
||||
// TODO Wallet型変数 wallet をWallet型のインスタンスで初期化してください。
|
||||
|
||||
// TODO walletのmoneyフィールドに10000を代入してください。
|
||||
|
||||
// TODO Atm型変数 atm をAtm型のインスタンスで初期化してください
|
||||
|
||||
/*
|
||||
* TODO atmの withdrawメソッドに以下の引数を渡して呼びだしてください
|
||||
* 第一引数 wallet、第二引数 100000
|
||||
*/
|
||||
|
||||
// TODO walletのmoneyフィールドを出力してください
|
||||
// ※ 値が110000になっていれば正解
|
||||
|
||||
/*
|
||||
* TODO atmの withdrawメソッドに以下の引数を渡して呼びだしてください
|
||||
* 第一引数 wallet、第二引数 100000
|
||||
* ※ 預金残高不足です。現金の引き出しに失敗しましたと出れば正解
|
||||
*/
|
||||
|
||||
// TODO walletのmoneyフィールドを出力してください
|
||||
// ※ 値が110000のまま変わっていなければ正解
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
23
Question11-ConstructorAndStatic/src/PTra11_03.java
Normal file
23
Question11-ConstructorAndStatic/src/PTra11_03.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* PTra11_03.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
|
||||
|
||||
public class PTra11_03 {
|
||||
public static void main(String[] args) {
|
||||
// ※ この問題はCatクラスにコンストラクタを作成してから解いてください。
|
||||
// TODO Cat型変数 cat1 を 引数なしでインスタンス化してください。
|
||||
|
||||
// TODO cat1のnameフィールドを出力してください
|
||||
// ※ タマと出力されれば正解
|
||||
|
||||
// TODO Cat型変数 cat2 を 引数にミケを渡してインスタンス化してください。
|
||||
|
||||
// TODO cat2のnameフィールドを出力してください
|
||||
// ※ ミケと出力されれば正解
|
||||
|
||||
}
|
||||
}
|
||||
23
Question11-ConstructorAndStatic/src/PTra11_04.java
Normal file
23
Question11-ConstructorAndStatic/src/PTra11_04.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* PTra11_04.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
public class PTra11_04 {
|
||||
public static void main(String[] args) {
|
||||
// ※この問題はStudentクラスを使用して解いてください。
|
||||
// TODO 生徒の名前に 太郎 を設定してください。
|
||||
|
||||
// TODO 教室の名前に A を設定してください。
|
||||
|
||||
// TODO 先生の名前に 山田 を設定してください。
|
||||
|
||||
// TODO studentProfileメソッドを実行してください。
|
||||
// ※ 太郎はA教室の生徒です と表示されれば正解
|
||||
|
||||
// TODO groupProfileメソッドを実行してください
|
||||
// ※ A教室の担任は山田先生です。 と表示されれば正解
|
||||
|
||||
}
|
||||
}
|
||||
17
Question11-ConstructorAndStatic/src/PTra11_05.java
Normal file
17
Question11-ConstructorAndStatic/src/PTra11_05.java
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* PTra11_05.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
public class PTra11_05 {
|
||||
public static void main(String[] args) {
|
||||
// ※ この問題はJamクラス、Toastクラスを完成させてから解いてください。
|
||||
// TODO Jam型のインスタンスを引数 ブルーベリー で作成してください
|
||||
|
||||
// TODO Toast型のインスタンスを作成してください。
|
||||
|
||||
// TODO 作成したToast型インスタンスからtasteメソッドを呼び出してください
|
||||
|
||||
}
|
||||
}
|
||||
23
Question11-ConstructorAndStatic/src/Student.java
Normal file
23
Question11-ConstructorAndStatic/src/Student.java
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
|
||||
public class Student {
|
||||
String name; // 生徒の名前
|
||||
static String group; // 教室の名前
|
||||
static String teacher; // 先生の名前
|
||||
|
||||
/**
|
||||
* 生徒のプロフィールを出力する
|
||||
*/
|
||||
void studentProfile() {
|
||||
System.out.println(this.name + "は" + group + "教室の生徒です");
|
||||
}
|
||||
|
||||
/**
|
||||
* 教室のプロフィールを出力する。
|
||||
*/
|
||||
static void groupProfile() {
|
||||
System.out.println(group + "教室の担任は" + teacher + "先生です。");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
20
Question11-ConstructorAndStatic/src/Toast.java
Normal file
20
Question11-ConstructorAndStatic/src/Toast.java
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
|
||||
public class Toast {
|
||||
|
||||
// TODO Jam型のフィールドjamを作成してください
|
||||
|
||||
/*
|
||||
* TODO 以下のコンストラクタを作成してください
|
||||
* 引数 :Jam型 jam
|
||||
* 処理 :引数のjamをjamフィールドに代入する
|
||||
*/
|
||||
|
||||
/*
|
||||
* TODO tasteメソッドを作成してください
|
||||
* 引数 :なし
|
||||
* 戻り値 :なし
|
||||
* 処理 :xx 味のトーストです。 出力する
|
||||
* ※ xxにはjamフィールドのmaterialの値が入る
|
||||
*/
|
||||
}
|
||||
22
Question11-ConstructorAndStatic/src/User.java
Normal file
22
Question11-ConstructorAndStatic/src/User.java
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
|
||||
public class User {
|
||||
String name;
|
||||
Wallet wallet;
|
||||
|
||||
/**
|
||||
* 引数で渡された金額を、walletフィールドのmoneyから引く
|
||||
* @param money
|
||||
*/
|
||||
void useMoney(int money) {
|
||||
this.wallet.money -= money;
|
||||
System.out.println(this.name +"は財布の中のお金を" + money + "円使用しました");
|
||||
}
|
||||
|
||||
/**
|
||||
* 財布の中の金額を出力する
|
||||
*/
|
||||
void confirmWallet() {
|
||||
System.out.println(this.name +"の財布の中の残額は" + this.wallet.money + "円です");
|
||||
}
|
||||
}
|
||||
5
Question11-ConstructorAndStatic/src/Wallet.java
Normal file
5
Question11-ConstructorAndStatic/src/Wallet.java
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
public class Wallet {
|
||||
int money;
|
||||
}
|
||||
Reference in New Issue
Block a user