Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2223S2#40 from manushridiv/withdrawFe…
Browse files Browse the repository at this point in the history
…ature

Added a Withdraw feature in switch case
  • Loading branch information
tyuyang authored Mar 15, 2023
2 parents bf6b481 + f7867d3 commit 9304282
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
1 change: 1 addition & 0 deletions data/save.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jen;0.0
3 changes: 3 additions & 0 deletions src/main/java/seedu/bankwithus/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ public float getAccountBalance() {
return balance;
}

public void setBalance(float balance) {
this.balance = balance;
}
}
37 changes: 28 additions & 9 deletions src/main/java/seedu/bankwithus/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/seedu/bankwithus/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void createScanner() {

/**
* Gets the next line of user input
*
*
* @return the next of user input
*/

Expand All @@ -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!");
}
}

0 comments on commit 9304282

Please sign in to comment.