From d50223dc4dc491008f82688da4392c186410c8fc Mon Sep 17 00:00:00 2001 From: ivs Date: Thu, 27 Mar 2025 14:49:42 +0800 Subject: [PATCH] Tutorial 7 --- T7Q1-2/T7Q1-2.iml | 11 +++++++++++ T7Q1-2/src/Bank.java | 23 +++++++++++++++++++++++ T7Q1-2/src/Check.java | 9 +++++++++ T7Q1-2/src/CheckingAccount.java | 14 ++++++++++++++ T7Q1-2/src/Main.java | 9 +++++++++ T7Q1/T7Q1.iml | 11 +++++++++++ T7Q1/src/Bank.java | 7 +++++++ T7Q1/src/Check.java | 9 +++++++++ T7Q1/src/CheckingAccount.java | 14 ++++++++++++++ T7Q1/src/Main.java | 9 +++++++++ 10 files changed, 116 insertions(+) create mode 100644 T7Q1-2/T7Q1-2.iml create mode 100644 T7Q1-2/src/Bank.java create mode 100644 T7Q1-2/src/Check.java create mode 100644 T7Q1-2/src/CheckingAccount.java create mode 100644 T7Q1-2/src/Main.java create mode 100644 T7Q1/T7Q1.iml create mode 100644 T7Q1/src/Bank.java create mode 100644 T7Q1/src/Check.java create mode 100644 T7Q1/src/CheckingAccount.java create mode 100644 T7Q1/src/Main.java diff --git a/T7Q1-2/T7Q1-2.iml b/T7Q1-2/T7Q1-2.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/T7Q1-2/T7Q1-2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/T7Q1-2/src/Bank.java b/T7Q1-2/src/Bank.java new file mode 100644 index 0000000..b20089d --- /dev/null +++ b/T7Q1-2/src/Bank.java @@ -0,0 +1,23 @@ +public class Bank { + private CheckingAccount account; + + public Bank() { + account = new CheckingAccount(); + } + public double cashCheck(Check check) { + double amount = check.getAmount(); + double balance = account.getBalance(); + if (balance < amount) { + account.addInsuficientFundFee(); + account.noteReturnedCheck(check); + return -1; + } + int checkNumber = check.getCheckNumber(); + account.addDebitTransaction(checkNumber, amount); + account.storePhotoOfCheck(check); + + return amount; + } + + private void returnCheck(Check check) {} +} diff --git a/T7Q1-2/src/Check.java b/T7Q1-2/src/Check.java new file mode 100644 index 0000000..cc8aee6 --- /dev/null +++ b/T7Q1-2/src/Check.java @@ -0,0 +1,9 @@ +public class Check { + public double getAmount() { + return 100.0; // any valid double + } + + public int getCheckNumber() { + return 1234; // any valid int + } +} diff --git a/T7Q1-2/src/CheckingAccount.java b/T7Q1-2/src/CheckingAccount.java new file mode 100644 index 0000000..526fce3 --- /dev/null +++ b/T7Q1-2/src/CheckingAccount.java @@ -0,0 +1,14 @@ +public class CheckingAccount { + public double getBalance() { + return 100.0; // any valid double + } + + public void addInsuficientFundFee() {} + + public void noteReturnedCheck(Check check) {} + + public void addDebitTransaction(int checknumber, double amount) {} + + public void storePhotoOfCheck(Check check) {} + +} diff --git a/T7Q1-2/src/Main.java b/T7Q1-2/src/Main.java new file mode 100644 index 0000000..efdf3e1 --- /dev/null +++ b/T7Q1-2/src/Main.java @@ -0,0 +1,9 @@ +public class Main { + public static void main(String[] args) { + System.out.println("Hello, World!"); + Bank bank = new Bank(); + Check check = new Check(); + bank.cashCheck(check); + System.out.println("Compiled successfully!"); + } +} \ No newline at end of file diff --git a/T7Q1/T7Q1.iml b/T7Q1/T7Q1.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/T7Q1/T7Q1.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/T7Q1/src/Bank.java b/T7Q1/src/Bank.java new file mode 100644 index 0000000..3487f88 --- /dev/null +++ b/T7Q1/src/Bank.java @@ -0,0 +1,7 @@ +public class Bank { + public double cashCheck(Check check) { + return 0.0; + } + + private void returnCheck(Check check) {} +} diff --git a/T7Q1/src/Check.java b/T7Q1/src/Check.java new file mode 100644 index 0000000..cc8aee6 --- /dev/null +++ b/T7Q1/src/Check.java @@ -0,0 +1,9 @@ +public class Check { + public double getAmount() { + return 100.0; // any valid double + } + + public int getCheckNumber() { + return 1234; // any valid int + } +} diff --git a/T7Q1/src/CheckingAccount.java b/T7Q1/src/CheckingAccount.java new file mode 100644 index 0000000..526fce3 --- /dev/null +++ b/T7Q1/src/CheckingAccount.java @@ -0,0 +1,14 @@ +public class CheckingAccount { + public double getBalance() { + return 100.0; // any valid double + } + + public void addInsuficientFundFee() {} + + public void noteReturnedCheck(Check check) {} + + public void addDebitTransaction(int checknumber, double amount) {} + + public void storePhotoOfCheck(Check check) {} + +} diff --git a/T7Q1/src/Main.java b/T7Q1/src/Main.java new file mode 100644 index 0000000..efdf3e1 --- /dev/null +++ b/T7Q1/src/Main.java @@ -0,0 +1,9 @@ +public class Main { + public static void main(String[] args) { + System.out.println("Hello, World!"); + Bank bank = new Bank(); + Check check = new Check(); + bank.cashCheck(check); + System.out.println("Compiled successfully!"); + } +} \ No newline at end of file