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 {