diff --git a/data/save.txt b/data/save.txt new file mode 100644 index 0000000000..e03d8678c6 --- /dev/null +++ b/data/save.txt @@ -0,0 +1 @@ +jen;0.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 d3111f856e..c65e6fdd52 100644 --- a/src/main/java/seedu/bankwithus/Parser.java +++ b/src/main/java/seedu/bankwithus/Parser.java @@ -13,6 +13,13 @@ public Parser(BankWithUs bwu) { this.bwu = bwu; } + public float parseWithdrawAmt(String args) { + float withdrawAmt = Float.parseFloat(args); + float currBal = bwu.accounts.accounts.get(0).balance; + float final_bal = currBal-withdrawAmt; + return final_bal; + } + /** * Parses the user input into command and arguments. */ @@ -24,18 +31,30 @@ public void parseUserInput(String input) throws CommandNotFoundException { String args = split.length == 2 ? split[1] : ""; Ui screen = new Ui(); switch (command) { - case "exit": - bwu.isExitEntered = true; - break; - case "view-account": - String accDetails = bwu.accounts.getAllAccountDetails(); - screen.viewAccount(accDetails); - break; - default: - throw new CommandNotFoundException(); + case "exit": + bwu.isExitEntered = true; + break; + case "view-account": + String accDetails = bwu.accounts.getAllAccountDetails(); + screen.viewAccount(accDetails); + break; + case "withdraw": + float final_bal = parseWithdrawAmt(args); + if(final_bal > -1) { + bwu.accounts.accounts.get(0).setBalance(final_bal); + screen.showBal(final_bal); + } else { + System.out.println("You do not have sufficient Balance"); + } + break; + default: + throw new CommandNotFoundException(); } + } + + /** * This method reads any existing file and add the saved data * into current programme diff --git a/src/main/java/seedu/bankwithus/Ui.java b/src/main/java/seedu/bankwithus/Ui.java index 98881d8f2a..3b7782bcb6 100644 --- a/src/main/java/seedu/bankwithus/Ui.java +++ b/src/main/java/seedu/bankwithus/Ui.java @@ -40,7 +40,7 @@ public void createScanner() { /** * Gets the next line of user input - * + * * @return the next of user input */ @@ -56,13 +56,20 @@ public void closeScanner() { this.scanner.close(); } - public void printLine() {System.out.println("----------------------------");} + public void printLine() { + System.out.println("----------------------------"); + } + public void viewAccount(String accDetails) { String name = accDetails.split(";")[0]; String bal = accDetails.split(";")[1]; printLine(); System.out.println("Name: " + name); - System.out.println("Balance: $"+bal); + System.out.println("Balance: $" + bal); printLine(); } -} + + public void showBal(float finalBal) { + System.out.println("You have $" + String.valueOf(finalBal) + " remaining!"); + } +} \ No newline at end of file