Skip to content

Commit

Permalink
Fix typo exception
Browse files Browse the repository at this point in the history
  • Loading branch information
ChongXern committed Mar 22, 2024
1 parent f7e2dd1 commit a58ba0b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
3 changes: 0 additions & 3 deletions data/data.txt
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

public class IncompletePromptException extends Exception {
public static final String[] INSTRUCTIONS = {
"add-inflow", "add-outflow", "delete-inflow", "delete-outflow",
"login", "quit", "view-history"};
"add-inflow", "add-outflow", "delete-inflow", "delete-outflow", "quit"};
private boolean isTypo = false;
private boolean isIncomplete = false;
private boolean isUnknown = false;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/financialtransactions/TransactionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,31 @@ public String toString() {
return "Inflows:\n" + inflows.toString() + "\nOutflows:\n" + outflows.toString();
}

public String showLastNTransactions(int n) throws Exception{
public String showLastNTransactions(int n) throws Exception {
int listSize = transactionList.getTransactionListSize();
if (n > listSize) {
throw new Exception("Invalid index");
}
int index = 1;
String returnedText = "Inflows:\nTransactions:\n";
StringBuilder returnedText = new StringBuilder("Inflows:\nTransactions:\n");
for (int i = listSize - 1; i > listSize - n - 1; i--) {
Transaction<?> transaction = transactionList.getNthTransaction(i);
if (transaction instanceof Inflow) {
returnedText += String.format("%d) %s\n", index, transactionList.getNthTransaction(i).toString());
returnedText.append(String.format("%d) %s\n", index, transactionList.getNthTransaction(i).toString()));
index++;
}
}

index = 1;
returnedText += "\nOutflows:\nTransactions:\n";
returnedText.append("\nOutflows:\nTransactions:\n");
for (int i = listSize - 1; i > listSize - n - 1; i--) {
Transaction<?> transaction = transactionList.getNthTransaction(i);
if (transaction instanceof Outflow) {
returnedText += String.format("%d) %s\n", index, transactionList.getNthTransaction(i).toString());
returnedText.append(String.format("%d) %s\n", index, transactionList.getNthTransaction(i).toString()));
index++;
}
}
return returnedText;
return returnedText.toString();
}

public String toSave() {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public BaseCommand parseCommand(String command) throws IncompletePromptException
case "quit":
return new ExitCommand(commandParts);
default:
throw new Exception("Invalid command");
throw new IncompletePromptException(command);
// throw new Exception("Invalid command");
}
}
}
3 changes: 1 addition & 2 deletions src/main/java/user/InactivityTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public void checkTimeElapsed() throws InactivityTimeoutException {
if (timeDifference >= INACTIVITY_TIME) {
System.out.println("Sorry, your session has ended. Please log in again.");
throw new InactivityTimeoutException(true, false);
}
else if (timeDifference >= INACTIVITY_TIME - GRACE_TIME) {
} else if (timeDifference >= INACTIVITY_TIME - GRACE_TIME) {
throw new InactivityTimeoutException(false, true);
}
}
Expand Down

0 comments on commit a58ba0b

Please sign in to comment.