forked from nus-cs2113-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from hshiah/temp
Finish all user stories for v2.0
- Loading branch information
Showing
11 changed files
with
161 additions
and
39 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/main/java/seedu/financialplanner/commands/DeleteGoalCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/seedu/financialplanner/commands/WishListCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters