From 2ba8c0543988132a554affabfdab2743a3bb5cc3 Mon Sep 17 00:00:00 2001 From: manushridiv Date: Wed, 15 Mar 2023 18:17:25 +0800 Subject: [PATCH] Added withdraw case --- data/save.txt | 1 + src/main/java/seedu/bankwithus/Account.java | 3 +++ src/main/java/seedu/bankwithus/Parser.java | 30 +++++++++++++-------- src/main/java/seedu/bankwithus/Ui.java | 11 ++++++++ 4 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 data/save.txt diff --git a/data/save.txt b/data/save.txt new file mode 100644 index 0000000000..d66d674e04 --- /dev/null +++ b/data/save.txt @@ -0,0 +1 @@ +jen;900.0 diff --git a/src/main/java/seedu/bankwithus/Account.java b/src/main/java/seedu/bankwithus/Account.java index 9fd5c4a77b..1d26aafbdf 100644 --- a/src/main/java/seedu/bankwithus/Account.java +++ b/src/main/java/seedu/bankwithus/Account.java @@ -25,4 +25,7 @@ public float getAccountBalance() { return balance; } + public void setBalance(float balance) { + this.balance = balance; + } } diff --git a/src/main/java/seedu/bankwithus/Parser.java b/src/main/java/seedu/bankwithus/Parser.java index 7eb75f3062..776916eaa4 100644 --- a/src/main/java/seedu/bankwithus/Parser.java +++ b/src/main/java/seedu/bankwithus/Parser.java @@ -22,18 +22,26 @@ public void parseUserInput(String input) throws CommandNotFoundException { String[] split = input.trim().split("\\s+", 2); String command = split[0]; String args = split.length == 2 ? split[1] : ""; - - if (command.equals("exit")) { - bwu.isExitEntered = true; - } else { - switch (command) { - case "exit": - bwu.isExitEntered = true; - break; - default: - throw new CommandNotFoundException(); - } + Ui screen = new Ui(); + switch (command) { + case "exit": + bwu.isExitEntered = true; + break; + case "view-account": + String accDetails = bwu.accounts.getAllAccountDetails(); + screen.viewAccount(accDetails); + break; + case "withdraw": + float withdrawAmt = Float.parseFloat(args); + float currBal = bwu.accounts.accounts.get(0).balance; + float final_bal = currBal-withdrawAmt; + bwu.accounts.accounts.get(0).setBalance(final_bal); + System.out.println("u have $" + String.valueOf(final_bal) + " remaining!"); + break; + default: + throw new CommandNotFoundException(); } + } /** diff --git a/src/main/java/seedu/bankwithus/Ui.java b/src/main/java/seedu/bankwithus/Ui.java index 60f3e714e8..c95cc8b42f 100644 --- a/src/main/java/seedu/bankwithus/Ui.java +++ b/src/main/java/seedu/bankwithus/Ui.java @@ -55,4 +55,15 @@ public String getNextLine() { public void closeScanner() { this.scanner.close(); } + + public void viewAccount(String accDetails) { + String name = accDetails.split(";")[0]; + String bal = accDetails.split(";")[1]; + System.out.println("----------------------------"); + System.out.println("Name: " + name); + System.out.println("Balance: $"+bal); + System.out.println("----------------------------"); + } } + +