diff options
author | Sudipto Mallick <smlckz@bccr> | 2024-01-10 15:59:05 +0530 |
---|---|---|
committer | Sudipto Mallick <smlckz@bccr> | 2024-01-10 15:59:05 +0530 |
commit | 87554cf575a4a92f00908a7cccfe6c92db2ef3ef (patch) | |
tree | d7e3f25e5c856e999fd98634132db5013055ee9d /java/code | |
parent | 5ea0ab6272277357c847ce324582e08cff58d134 (diff) | |
download | zadania-87554cf575a4a92f00908a7cccfe6c92db2ef3ef.tar.gz |
Incorporate changes in Java Assignment #12
As well as implement a shell script `tobedone` that shows how many assignments need to be done
Diffstat (limited to 'java/code')
-rw-r--r-- | java/code/BankAccountExample.java | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/java/code/BankAccountExample.java b/java/code/BankAccountExample.java index 487a564..d788755 100644 --- a/java/code/BankAccountExample.java +++ b/java/code/BankAccountExample.java @@ -26,17 +26,21 @@ class BankAccount { } long getAccountNo() { return accountNo; } double getBalance() { return balance; } + @Override + public boolean equals(Object o) { + return o != null && o instanceof BankAccount && accountNo == ((BankAccount)o).getAccountNo(); + } void deposit(double amount) throws IllegalArgumentException { if (amount < 0.0) throw new IllegalArgumentException( - "Can not deposit negative amount of money. Use withdraw() instead."); + "Can not deposit negative amount of money. Perform withdrawal instead."); balance += amount; } static String formatBalance(double value) { return String.format("%.2f", value); } void withdraw(double amount) throws Exception { if (amount < 0.0) throw new IllegalArgumentException( - "Can not withdraw negative amount of money. Use deposit() instead."); + "Can not withdraw negative amount of money. Perform deposit instead."); else if (amount > balance) throw new Exception( "Available balance: " + formatBalance(balance) + @@ -68,7 +72,8 @@ class BankAccountExample { " 2. Display bank account details\n" + " 3. Deposit money\n" + " 4. Withdraw money\n" + - " 5. Exit\n"); + " 5. Close bank account\n" + + " 6. Exit\n"); } static BankAccount findAccount(Scanner sc, ArrayList<BankAccount> accounts) { System.out.print("Enter account number: "); @@ -145,6 +150,18 @@ class BankAccountExample { } break; case 5: + ac = findAccount(sc, accounts); + if (ac == null) continue; + System.out.print("Are you sure about closing your account (y/n): "); + var response = sc.nextLine(); + if (!response.equalsIgnoreCase("y")) { + System.out.println("Account closing aborted."); + continue; + } + accounts.remove(ac); + System.out.println("Account closing successful."); + break; + case 6: System.out.println("Bye."); return; default: |