Skip to content

Commit

Permalink
Merge pull request #143 from hshiah/temp
Browse files Browse the repository at this point in the history
Finish all user stories for v2.0
  • Loading branch information
hshiah authored Nov 1, 2023
2 parents 3813917 + a026d6c commit 0544e3f
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package seedu.financialplanner.commands;

import seedu.financialplanner.goal.WishList;
import seedu.financialplanner.utils.Ui;
import java.util.logging.Level;
import java.util.logging.Logger;
import seedu.financialplanner.goal.Goal;
public class DeleteGoalCommand extends Command {
private static final Logger logger = Logger.getLogger("Financial Planner Logger");
private final int index;
public DeleteGoalCommand(RawCommand rawCommand) throws IllegalArgumentException {
String stringIndex;
if (rawCommand.args.size() == 1) {
stringIndex = rawCommand.args.get(0);
} else {
throw new IllegalArgumentException("Incorrect arguments.");
}

try {
logger.log(Level.INFO, "Parsing index as integer");
index = Integer.parseInt(stringIndex);
} catch (IllegalArgumentException e) {
logger.log(Level.WARNING, "Invalid argument for index");
throw new IllegalArgumentException("Index must be an integer");
}

if (index <= 0) {
logger.log(Level.WARNING, "Invalid value for index");
throw new IllegalArgumentException("Index must be within the list");
}

if (index > WishList.getInstance().list.size() + 1) {
logger.log(Level.WARNING, "Invalid value for index");
throw new IllegalArgumentException("Index exceed the list size");
}
rawCommand.extraArgs.remove("i");
if (!rawCommand.extraArgs.isEmpty()) {
String unknownExtraArgument = new java.util.ArrayList<>(rawCommand.extraArgs.keySet()).get(0);
logger.log(Level.WARNING, "Invalid extra arguments found");
throw new IllegalArgumentException(String.format("Unknown extra argument: %s", unknownExtraArgument));
}
}

@Override
public void execute() {
Goal goalToDelete = WishList.getInstance().list.get(index-1);
WishList.getInstance().deleteGoal(index-1);
Ui.getInstance().showMessage("You have deleted " + goalToDelete);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import seedu.financialplanner.utils.Ui;
import java.util.logging.Level;
import java.util.logging.Logger;

import seedu.financialplanner.reminder.Reminder;
public class DeleteReminderCommand extends Command{
private static final Logger logger = Logger.getLogger("Financial Planner Logger");
private final int index;
Expand All @@ -24,7 +24,7 @@ public DeleteReminderCommand(RawCommand rawCommand) throws IllegalArgumentExcept
throw new IllegalArgumentException("Index must be an integer");
}

if (index == 0) {
if (index <= 0) {
logger.log(Level.WARNING, "Invalid value for index");
throw new IllegalArgumentException("Index must be within the list");
}
Expand All @@ -33,7 +33,6 @@ public DeleteReminderCommand(RawCommand rawCommand) throws IllegalArgumentExcept
logger.log(Level.WARNING, "Invalid value for index");
throw new IllegalArgumentException("Index exceed the list size");
}
rawCommand.extraArgs.remove("i");
if (!rawCommand.extraArgs.isEmpty()) {
String unknownExtraArgument = new java.util.ArrayList<>(rawCommand.extraArgs.keySet()).get(0);
logger.log(Level.WARNING, "Invalid extra arguments found");
Expand All @@ -43,7 +42,8 @@ public DeleteReminderCommand(RawCommand rawCommand) throws IllegalArgumentExcept

@Override
public void execute() {
ReminderList.getInstance().deleteReminder(index);
Ui.getInstance().showMessage("You have deleted " + ReminderList.getInstance().list.get(index-1));
Reminder reminderToDelete = ReminderList.getInstance().list.get(index-1);
ReminderList.getInstance().deleteReminder(index-1);
Ui.getInstance().showMessage("You have deleted " + reminderToDelete);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package seedu.financialplanner.commands;
import seedu.financialplanner.reminder.ReminderList;

import seedu.financialplanner.goal.WishList;
import seedu.financialplanner.utils.Ui;
public class UnmarkReminderCommand extends Command{
import seedu.financialplanner.cashflow.CashflowList;
import seedu.financialplanner.goal.Goal;
import seedu.financialplanner.enumerations.ExpenseType;
public class MarkGoalCommand extends Command {
private final int index;
public UnmarkReminderCommand(RawCommand rawCommand) throws IllegalArgumentException {
public MarkGoalCommand(RawCommand rawCommand) throws IllegalArgumentException {
String stringIndex;
if (rawCommand.args.size() == 1) {
stringIndex = rawCommand.args.get(0);
Expand All @@ -19,7 +23,7 @@ public UnmarkReminderCommand(RawCommand rawCommand) throws IllegalArgumentExcept
if (index == 0) {
throw new IllegalArgumentException("Index must be within the list");
}
if (index > ReminderList.getInstance().list.size()+1){
if (index > WishList.getInstance().list.size()+1){
throw new IllegalArgumentException("Index exceed the list size");
}
rawCommand.extraArgs.remove("i");
Expand All @@ -31,7 +35,9 @@ public UnmarkReminderCommand(RawCommand rawCommand) throws IllegalArgumentExcept

@Override
public void execute() {
ReminderList.getInstance().list.get(index-1).unmark();
Ui.getInstance().showMessage("You have unmarked "+ReminderList.getInstance().list.get(index-1));
Goal goal = WishList.getInstance().list.get(index-1);
goal.markAsDone();
Ui.getInstance().showMessage("You have achieved " + goal + System.lineSeparator() + "Congratulations!");
CashflowList.getInstance().addExpense(goal.getAmount(), ExpenseType.OTHERS, 0, goal.getLabel());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package seedu.financialplanner.commands;

import seedu.financialplanner.reminder.ReminderList;
import seedu.financialplanner.utils.Ui;
public class ReminderListCommand extends Command{
Expand All @@ -11,6 +12,6 @@ public void execute() {
Ui ui = Ui.getInstance();
ReminderList reminderList = ReminderList.getInstance();
ui.showMessage("Here is your reminder list:");
ui.showMessage(reminderList.list.toString());
ui.showMessage(reminderList.toString());
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package seedu.financialplanner.commands;
import seedu.financialplanner.goal.Goal;
import seedu.financialplanner.goal.GoalList;
import seedu.financialplanner.goal.WishList;
import seedu.financialplanner.utils.Ui;

public class SetGoalCommand extends Command {
private final String goal;
private int amount;
private final String label;
private final int amount;

public SetGoalCommand(RawCommand rawCommand) throws IllegalArgumentException {
String labelString = String.join(" ", rawCommand.args);
Expand All @@ -21,7 +21,7 @@ public SetGoalCommand(RawCommand rawCommand) throws IllegalArgumentException {
if(!rawCommand.extraArgs.containsKey("l")){
throw new IllegalArgumentException("Please specify the content of the goal");
}
goal = rawCommand.extraArgs.get("l");
label = rawCommand.extraArgs.get("l");
rawCommand.extraArgs.remove("l");
if(!rawCommand.extraArgs.isEmpty()){
String unknownExtraArgument = new java.util.ArrayList<>(rawCommand.extraArgs.keySet()).get(0);
Expand All @@ -31,7 +31,8 @@ public SetGoalCommand(RawCommand rawCommand) throws IllegalArgumentException {

@Override
public void execute() {
GoalList.INSTANCE.list.add(new Goal(goal, amount));
Ui.getInstance().showMessage("Set Goal Successfully!");
Goal goal = new Goal(label, amount);
WishList.getInstance().list.add(goal);
Ui.getInstance().showMessage("You have added " + goal);
}
}
17 changes: 17 additions & 0 deletions src/main/java/seedu/financialplanner/commands/WishListCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package seedu.financialplanner.commands;

import seedu.financialplanner.goal.WishList;
import seedu.financialplanner.utils.Ui;
public class WishListCommand extends Command {
public WishListCommand(RawCommand rawCommand) throws IllegalArgumentException{

}

@Override
public void execute() {
Ui ui = Ui.getInstance();
WishList wishList = WishList.getInstance();
ui.showMessage("Here is your wish list:");
ui.showMessage(wishList.toString());
}
}
13 changes: 8 additions & 5 deletions src/main/java/seedu/financialplanner/goal/Goal.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package seedu.financialplanner.goal;

public class Goal {
private String label;
private int amount;
private final String label;
private final int amount;
private boolean isDone = false;

public Goal(String label, int amount) {
Expand All @@ -11,7 +11,7 @@ public Goal(String label, int amount) {
}

public String toString() {
String status = isDone ? "Done" : "Not Done";
String status = isDone ? "Achieved" : "Not Achieved";
return "Goal " + System.lineSeparator()+ " Label: " + label + System.lineSeparator() + " Amount: " +
amount + System.lineSeparator() + " Status: "+status;
}
Expand All @@ -20,8 +20,11 @@ public void markAsDone() {
this.isDone = true;
}

public void unmark() {
this.isDone = false;
public String getLabel() {
return this.label;
}
public int getAmount() {
return this.amount;
}
public String formatString() {
String status = isDone ? "Done" : "Not Done";
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/seedu/financialplanner/goal/GoalList.java

This file was deleted.

35 changes: 35 additions & 0 deletions src/main/java/seedu/financialplanner/goal/WishList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package seedu.financialplanner.goal;

import java.util.ArrayList;
public class WishList {
private static WishList wishList = null;
public final ArrayList<Goal> list = new ArrayList<>();
private WishList() {
}

public static WishList getInstance() {
if (wishList == null) {
wishList = new WishList();
}
return wishList;
}

public void load(Goal goal) {
list.add(goal);
}

public void deleteGoal(int index) {
int existingListSize = list.size();
int listIndex = index;
assert listIndex >= 0 && listIndex < existingListSize;
Goal toRemove = list.get(listIndex);
list.remove(listIndex);
}
public String toString() {
String result = "";
for (int i = 0; i < list.size(); i++) {
result += String.format("%d. %s\n", i + 1, list.get(i));
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ public void load(Reminder reminder) {
}
public void deleteReminder(int index) {
int existingListSize = list.size();
int listIndex = index - 1;
int listIndex = index;
assert listIndex >= 0 && listIndex < existingListSize;
Reminder toRemove = list.get(listIndex);
list.remove(listIndex);

}

public String toString() {
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/seedu/financialplanner/utils/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
import seedu.financialplanner.commands.SetGoalCommand;
import seedu.financialplanner.commands.BalanceCommand;
import seedu.financialplanner.commands.DeleteStockCommand;
import seedu.financialplanner.commands.MarkGoalCommand;
import seedu.financialplanner.commands.MarkReminderCommand;
import seedu.financialplanner.commands.DeleteGoalCommand;
import seedu.financialplanner.commands.DeleteReminderCommand;
import seedu.financialplanner.commands.ReminderListCommand;
import seedu.financialplanner.commands.WishListCommand;
import seedu.financialplanner.exceptions.FinancialPlannerException;

import java.util.ArrayList;
Expand All @@ -41,6 +47,12 @@ public class Parser {
private static final String LIST_COMMAND = "list";
private static final String SET_GOAL_COMMAND = "set";
private static final String BALANCE_COMMAND = "balance";
private static final String MARK_GOAL_COMMAND = "markgoal";
private static final String MARK_REMINDER_COMMAND = "markreminder";
private static final String DELETE_GOAL_COMMAND = "deletegoal";
private static final String DELETE_REMINDER_COMMAND = "deletereminder";
private static final String REMINDER_LIST_COMMAND = "reminderlist";
private static final String WISH_LIST_COMMAND = "wishlist";

public static Command parseCommand(String input) throws FinancialPlannerException {
RawCommand rawCommand = parseRawCommand(input);
Expand Down Expand Up @@ -77,6 +89,18 @@ public static Command parseCommand(RawCommand rawCommand) throws FinancialPlanne
return new SetGoalCommand(rawCommand);
case BALANCE_COMMAND:
return new BalanceCommand(rawCommand);
case MARK_GOAL_COMMAND:
return new MarkGoalCommand(rawCommand);
case MARK_REMINDER_COMMAND:
return new MarkReminderCommand(rawCommand);
case DELETE_GOAL_COMMAND:
return new DeleteGoalCommand(rawCommand);
case DELETE_REMINDER_COMMAND:
return new DeleteReminderCommand(rawCommand);
case REMINDER_LIST_COMMAND:
return new ReminderListCommand(rawCommand);
case WISH_LIST_COMMAND:
return new WishListCommand(rawCommand);
default:
return new InvalidCommand();
}
Expand Down

0 comments on commit 0544e3f

Please sign in to comment.