diff options
-rw-r--r-- | java/code/BankAccountExample.java | 23 | ||||
-rw-r--r-- | java/state.sql | 6 | ||||
-rw-r--r-- | java/tobedone | 7 |
3 files changed, 29 insertions, 7 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: diff --git a/java/state.sql b/java/state.sql index 462d787..62023e0 100644 --- a/java/state.sql +++ b/java/state.sql @@ -16,7 +16,7 @@ INSERT INTO `assignments` VALUES ('StaticExecution', 1, 1, 1, 1), ('SingletonExample', 1, 1, 0, 1), ('StudentsArray', 1, 0, 0, 1), - ('BankAccountExample', 0, 0, 0, 1), + ('BankAccountExample', 1, 0, 0, 1), ('ShapeAreaCalculations', 1, 0, 0, 0), ('AbstractShapeCalculations', 1, 0, 0, 0), ('FamilyExample', 0, 0, 0, 0), @@ -30,6 +30,4 @@ INSERT INTO `assignments` VALUES ('CustomExceptionExample', 0, 0, 0, 0), ('ThreadsExample', 0, 0, 0, 0); -.mode markdown -SELECT * FROM `assignments`; - +-- SELECT * FROM `assignments`; diff --git a/java/tobedone b/java/tobedone new file mode 100644 index 0000000..dd34705 --- /dev/null +++ b/java/tobedone @@ -0,0 +1,7 @@ +#!/bin/sh + +{ + cat state.sql + printf '.mode column\n' + printf 'SELECT name FROM `assignments` WHERE NOT %s;\n' "${1:-code}" +} | sqlite3 | tail -n +3 |