From a58ba233062db2b7b06980d033fd9d6371f317e3 Mon Sep 17 00:00:00 2001 From: ChongXern Date: Fri, 12 Apr 2024 13:55:36 +0800 Subject: [PATCH] Fix issues #126, #104 and #95 --- src/main/java/command/ViewHistoryCommand.java | 12 +++++++++--- .../financialtransactions/TransactionManager.java | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/command/ViewHistoryCommand.java b/src/main/java/command/ViewHistoryCommand.java index 6fd558a38f..db72747b92 100644 --- a/src/main/java/command/ViewHistoryCommand.java +++ b/src/main/java/command/ViewHistoryCommand.java @@ -9,13 +9,19 @@ public ViewHistoryCommand(String[] commandParts) { super(false,commandParts); } - public String execute(TransactionManager manager) throws Exception{ + public String execute(TransactionManager manager) throws Exception { //@@author Kishen271828 - //String numTransactionsString = null; int numTransactions = 0; if (commandParts[1].startsWith("n/")) { String numTransactionsString = commandParts[1].substring(2); - numTransactions = Integer.parseInt(numTransactionsString); + try { + numTransactions = Integer.parseInt(numTransactionsString); + if (numTransactions <= 0) { + throw new IllegalArgumentException("Sorry, please input a positive index."); + } + } catch (NumberFormatException e) { + throw new IncorrectCommandSyntaxException(commandParts[0]); + } } else if (commandParts[1].equals("all")) { numTransactions = manager.getTransactionListSize(); } else { diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java index 40a3d4fea1..b6ca9847b4 100644 --- a/src/main/java/financialtransactions/TransactionManager.java +++ b/src/main/java/financialtransactions/TransactionManager.java @@ -107,7 +107,7 @@ public Inflow editInflow(int index, Transaction updatedTransaction) throws Ex inflows.editTransactionIndex(numOfInflows - index, (Inflow) updatedTransaction); inflows.sortTransactions(); - return (Inflow) transactionEdited; + return transactionEdited; } public Outflow editOutflow(int index, Transaction updatedTransaction) throws Exception {