Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2223S2#41 from tyuyang/master
Browse files Browse the repository at this point in the history
Fixed checkstyle errors from merge nus-cs2113-AY2223S2#40
  • Loading branch information
xiaoge26 authored Mar 15, 2023
2 parents 9304282 + 057b015 commit 5a6e071
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
49 changes: 30 additions & 19 deletions src/main/java/seedu/bankwithus/Parser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.bankwithus;

import seedu.bankwithus.exceptions.CommandNotFoundException;
import seedu.bankwithus.exceptions.NegativeAmountException;

import java.io.File;
import java.io.IOException;
Expand All @@ -13,11 +14,14 @@ public Parser(BankWithUs bwu) {
this.bwu = bwu;
}

public float parseWithdrawAmt(String args) {
public float parseWithdrawAmt(String args) throws NegativeAmountException {
float withdrawAmt = Float.parseFloat(args);
if (withdrawAmt < 0) {
throw new NegativeAmountException();
}
float currBal = bwu.accounts.accounts.get(0).balance;
float final_bal = currBal-withdrawAmt;
return final_bal;
float finalBal = currBal-withdrawAmt;
return finalBal;
}

/**
Expand All @@ -31,24 +35,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;
case "withdraw":
float final_bal = parseWithdrawAmt(args);
if(final_bal > -1) {
bwu.accounts.accounts.get(0).setBalance(final_bal);
screen.showBal(final_bal);
case "exit":
bwu.isExitEntered = true;
break;
case "view-account":
String accDetails = bwu.accounts.getAllAccountDetails();
screen.viewAccount(accDetails);
break;
case "withdraw":
try {
float finalBal = parseWithdrawAmt(args);
if(finalBal >= 0) {
bwu.accounts.accounts.get(0).setBalance(finalBal);
screen.showBal(finalBal);
} else {
System.out.println("You do not have sufficient Balance");
screen.showInsufficientBalanceMessage();
}
break;
default:
throw new CommandNotFoundException();
} catch (NumberFormatException e) {
screen.showNumberFormatError();
} catch (NegativeAmountException e) {
screen.showNegativeAmountError();
}
break;
default:
throw new CommandNotFoundException();
}

}
Expand All @@ -71,5 +81,6 @@ public void parseSavedFile(AccountList list) throws IOException {
String balance = splitDetails[1];
list.addAccount(name, balance);
}
myReader.close();
}
}
10 changes: 9 additions & 1 deletion src/main/java/seedu/bankwithus/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,12 @@ public void viewAccount(String accDetails) {
public void showBal(float finalBal) {
System.out.println("You have $" + String.valueOf(finalBal) + " remaining!");
}
}

public void showNegativeAmountError() {
System.out.println("Negative number entered!");
}

public void showInsufficientBalanceMessage() {
System.out.println("You do not have sufficient Balance");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package seedu.bankwithus.exceptions;

/**
* Thrown when negative number is entered when not supposed to
*/
public class NegativeAmountException extends Exception {

}
1 change: 0 additions & 1 deletion text-ui-test/data/save.txt

This file was deleted.

0 comments on commit 5a6e071

Please sign in to comment.