forked from nusCS2113-AY1819S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
422 additions
and
45 deletions.
There are no files selected for viewing
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,5 @@ | ||
{ | ||
"appTitle" : "Financial Planner", | ||
"logLevel" : "INFO", | ||
"userPrefsFilePath" : "preferences.json" | ||
} |
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
63 changes: 63 additions & 0 deletions
63
src/main/java/seedu/planner/logic/commands/AddMonthlyLimitCommand.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,63 @@ | ||
package seedu.planner.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.planner.logic.parser.CliSyntax.PREFIX_MONEYFLOW; | ||
|
||
import seedu.planner.logic.CommandHistory; | ||
import seedu.planner.logic.commands.exceptions.CommandException; | ||
import seedu.planner.model.Model; | ||
import seedu.planner.model.record.Limit; | ||
|
||
|
||
|
||
/** | ||
* This Command is to set a limit for continuous month, which means the this limit is always for current month. | ||
* */ | ||
public class AddMonthlyLimitCommand extends Command { | ||
public static final String COMMAND_WORD = "addmonthlylimit"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Set a limit for continuous months. " | ||
+ "Parameters: " | ||
+ PREFIX_MONEYFLOW + "LIMIT_MONEY " + "\n" | ||
+ "Example: " | ||
+ COMMAND_WORD + " " | ||
+ PREFIX_MONEYFLOW + "500" + "\n"; | ||
|
||
public static final String MESSAGE_HAS_LIMIT = "There is already a monthly limit. \n"; | ||
public static final String MESSAGE_SUCCESS = "The monthly limit has been added. \n"; | ||
public static final String DATE_SPECIAL_FOR_MONTHLY = "01-01-9999"; | ||
|
||
|
||
|
||
private Limit limit; | ||
|
||
private String output; | ||
|
||
public AddMonthlyLimitCommand (Limit limitIn) { | ||
requireNonNull(limitIn); | ||
limit = limitIn; | ||
|
||
} | ||
|
||
|
||
@Override | ||
public CommandResult execute(Model model, CommandHistory history) throws CommandException { | ||
|
||
if (model.hasSameDateLimit(limit)) { | ||
throw new CommandException(MESSAGE_HAS_LIMIT); | ||
} | ||
|
||
model.addLimit(limit); | ||
output = MESSAGE_SUCCESS + model.generateLimitOutput(model.isExceededLimit(limit), | ||
model.getTotalSpend(limit), limit); | ||
model.commitFinancialPlanner(); | ||
return new CommandResult(output); | ||
} | ||
|
||
@Override | ||
public boolean equals (Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof seedu.planner.logic.commands.AddMonthlyLimitCommand // instanceof handles nulls | ||
&& limit.equals(((seedu.planner.logic.commands.AddMonthlyLimitCommand) other).limit)); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/seedu/planner/logic/commands/DeleteMonthlyLimitCommand.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,35 @@ | ||
package seedu.planner.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.planner.logic.CommandHistory; | ||
import seedu.planner.logic.commands.exceptions.CommandException; | ||
import seedu.planner.model.Model; | ||
import seedu.planner.model.record.Date; | ||
import seedu.planner.model.record.Limit; | ||
import seedu.planner.model.record.MoneyFlow; | ||
|
||
/** | ||
* This command is to remove the monthly limit stored inside the limitList. | ||
*/ | ||
|
||
public class DeleteMonthlyLimitCommand extends Command { | ||
public static final String COMMAND_WORD = "deletemonthlylimit"; | ||
public static final String MESSAGE_SUCCESS = "The monthly limit has been deleted"; | ||
public static final String MESSAGE_FAILURE = "There is no monthly limit!"; | ||
public static final Date DATE_SPECIAL_FOR_MONTHLY = new Date("01-01-9999"); | ||
|
||
private Limit monthlyLimit = new Limit(DATE_SPECIAL_FOR_MONTHLY, DATE_SPECIAL_FOR_MONTHLY, new MoneyFlow("-1")); | ||
@Override | ||
public CommandResult execute(Model model, CommandHistory history) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (!model.hasSameDateLimit(monthlyLimit)) { | ||
throw new CommandException(MESSAGE_FAILURE); | ||
} | ||
model.deleteLimit(model.getSameDatesLimit(DATE_SPECIAL_FOR_MONTHLY, DATE_SPECIAL_FOR_MONTHLY)); | ||
model.commitFinancialPlanner(); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
|
||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/seedu/planner/logic/commands/EditMonthlyLimitCommand.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,68 @@ | ||
package seedu.planner.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.planner.logic.parser.CliSyntax.PREFIX_MONEYFLOW; | ||
|
||
import seedu.planner.commons.core.Messages; | ||
import seedu.planner.logic.CommandHistory; | ||
import seedu.planner.logic.commands.exceptions.CommandException; | ||
import seedu.planner.model.Model; | ||
import seedu.planner.model.record.Limit; | ||
|
||
|
||
/** | ||
* This command is to modify the monthly limit money. | ||
*/ | ||
public class EditMonthlyLimitCommand extends Command { | ||
public static final String COMMAND_WORD = "editmonthlylimit"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edit the existing monthly limit. " | ||
+ "Parameters: " | ||
+ PREFIX_MONEYFLOW + "LIMIT_MONEY " + "\n" | ||
+ "Example: " | ||
+ COMMAND_WORD + " " | ||
+ PREFIX_MONEYFLOW + "500" + "\n"; | ||
|
||
|
||
public static final String MESSAGE_SUCCESS = "The monthly limit has been edited. \n"; | ||
|
||
|
||
|
||
private Limit limit; | ||
private Limit originalLimit; | ||
|
||
private String output; | ||
|
||
public EditMonthlyLimitCommand (Limit limitIn) { | ||
requireNonNull(limitIn); | ||
limit = limitIn; | ||
|
||
} | ||
|
||
|
||
@Override | ||
public CommandResult execute(Model model, CommandHistory history) throws CommandException { | ||
|
||
if (!model.hasSameDateLimit(limit)) { | ||
throw new CommandException(Messages.MESSAGE_LIMITS_DO_NOT_EXIST); | ||
} | ||
originalLimit = model.getSameDatesLimit(limit.getDateStart(), limit.getDateEnd()); | ||
model.updateLimit(originalLimit, limit); | ||
|
||
output = MESSAGE_SUCCESS + "Original Limit:\n" | ||
+ model.generateLimitOutput(model.isExceededLimit(originalLimit), | ||
model.getTotalSpend(originalLimit), originalLimit) | ||
+ "Modified Limit: \n" | ||
+ model.generateLimitOutput(model.isExceededLimit(limit), | ||
model.getTotalSpend(limit), limit); | ||
model.commitFinancialPlanner(); | ||
return new CommandResult(output); | ||
} | ||
|
||
@Override | ||
public boolean equals (Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof seedu.planner.logic.commands.EditMonthlyLimitCommand // instanceof handles nulls | ||
&& limit.equals(((seedu.planner.logic.commands.EditMonthlyLimitCommand) other).limit)); | ||
} | ||
} |
Oops, something went wrong.