-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add javadoc and update DG #131
Changes from 7 commits
27e3cf1
68bbd6e
6338f20
671c5da
f331a2c
62d9be7
f55ab08
214edc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,11 @@ | |
|
||
participant ":BudgetCommand" as BudgetCommand | ||
participant "<<class>>\nBudget" as Budget | ||
participant "<<class>>\nUi" as Ui | ||
participant "<<class>>\nUi" as UiClass | ||
participant ":Ui" as Ui | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice |
||
|
||
-> BudgetCommand: execute() | ||
BudgetCommand -> Ui: getInstance() | ||
BudgetCommand -> UiClass: getInstance() | ||
|
||
alt set | ||
BudgetCommand -> Budget: setBudget(budget) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package seedu.financialplanner; | ||
|
||
import seedu.financialplanner.cashflow.CashflowList; | ||
import seedu.financialplanner.commands.Command; | ||
import seedu.financialplanner.commands.ExitCommand; | ||
import seedu.financialplanner.exceptions.FinancialPlannerException; | ||
|
@@ -10,21 +11,35 @@ | |
|
||
import java.time.LocalDate; | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very good comments 💯 |
||
* Represents the main class for the Financial Planner. | ||
* It manages commands and user interactions. | ||
*/ | ||
public class FinancialPlanner { | ||
private static final LocalDate date = LocalDate.now(); | ||
private static final String FILE_PATH = "data/data.txt"; | ||
private final Storage storage = Storage.getInstance(); | ||
private final Ui ui = Ui.getInstance(); | ||
private final WatchList watchList = WatchList.getInstance(); | ||
private final CashflowList cashflowList = CashflowList.getInstance(); | ||
|
||
private FinancialPlanner() { | ||
} | ||
|
||
/** | ||
* The main starting point of the Financial Planner. | ||
* | ||
* @param args Unused. | ||
*/ | ||
public static void main(String[] args) { | ||
FinancialPlannerLogger.initialise(); | ||
new FinancialPlanner().run(); | ||
} | ||
|
||
/** | ||
* Loads storage from save file and starts the Financial Planner. | ||
* Saves the storage to save file upon exit. | ||
*/ | ||
public void run() { | ||
try { | ||
storage.load(FILE_PATH, date); | ||
|
@@ -50,6 +65,9 @@ public void run() { | |
ui.exitMessage(); | ||
} | ||
|
||
/** | ||
* Saves existing data to the save file. | ||
*/ | ||
public void save() { | ||
try { | ||
storage.save(FILE_PATH); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,22 +2,41 @@ | |
|
||
import java.text.DecimalFormat; | ||
|
||
/** | ||
* Represents the monthly budget. | ||
*/ | ||
public abstract class Budget { | ||
private static final int MONTH = 30; | ||
private static double initialBudget = 0; | ||
private static double currentBudget = 0; | ||
|
||
/** | ||
* Sets the monthly budget equal to amount. | ||
* | ||
* @param amount The monthly budget to be set | ||
*/ | ||
public static void setBudget(double amount) { | ||
initialBudget = amount; | ||
currentBudget = amount; | ||
assert initialBudget == currentBudget : "Initial and current budget should be the same"; | ||
assert initialBudget != 0 && currentBudget != 0 : "Initial and current budget should not be 0"; | ||
} | ||
|
||
/** | ||
* Returns the initial budget set. | ||
* | ||
* @return The initial budget. | ||
*/ | ||
public static double getInitialBudget() { | ||
return initialBudget; | ||
} | ||
|
||
/** | ||
* Updates initial budget to the new budget and updates the current budget | ||
* with the difference between the old initial budget and new initial budget. | ||
* | ||
* @param budget The budget to be updated to. | ||
*/ | ||
public static void updateBudget(double budget) { | ||
double diff; | ||
if (budget > initialBudget) { | ||
|
@@ -32,50 +51,104 @@ public static void updateBudget(double budget) { | |
assert initialBudget == budget : "Initial budget should be equal to updated budget"; | ||
} | ||
|
||
/** | ||
* Returns the current budget. | ||
* | ||
* @return The current budget. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think javadocs for getters and setters are necessary :((( |
||
public static double getCurrentBudget() { | ||
return currentBudget; | ||
} | ||
|
||
/** | ||
* Returns the current budget in 2 decimal places after converting | ||
* it into a string. | ||
* | ||
* @return The current budget in string format. | ||
*/ | ||
public static String getCurrentBudgetString() { | ||
DecimalFormat decimalFormat = new DecimalFormat("####0.00"); | ||
return decimalFormat.format(Cashflow.round(currentBudget, 2)); | ||
} | ||
|
||
/** | ||
* Returns the initial budget in 2 decimal places after converting | ||
* it into a string. | ||
* | ||
* @return The initial budget in string format. | ||
*/ | ||
public static String getInitialBudgetString() { | ||
DecimalFormat decimalFormat = new DecimalFormat("####0.00"); | ||
return decimalFormat.format(Cashflow.round(initialBudget, 2)); | ||
} | ||
|
||
/** | ||
* Deducts the current budget by the amount given. | ||
* | ||
* @param amount The amount to be deducted. | ||
*/ | ||
public static void deduct(double amount) { | ||
Budget.currentBudget -= amount; | ||
currentBudget -= amount; | ||
} | ||
|
||
/** | ||
* Loads the budget from the save file. | ||
* | ||
* @param initial The saved initial budget. | ||
* @param current The saved current budget. | ||
*/ | ||
public static void load(double initial, double current) { | ||
initialBudget = initial; | ||
currentBudget = current; | ||
} | ||
|
||
/** | ||
* Checks if there is a budget. | ||
* | ||
* @return True if there is a budget set, false otherwise. | ||
*/ | ||
public static boolean hasBudget() { | ||
return initialBudget != 0; | ||
} | ||
|
||
/** | ||
* Returns a string representation of the budget to be saved to the save file. | ||
* | ||
* @return A string representation of the budget. | ||
*/ | ||
public static String formatString() { | ||
return "B | " + initialBudget + " | " + currentBudget; | ||
} | ||
|
||
/** | ||
* Deletes an existing budget. | ||
*/ | ||
public static void deleteBudget() { | ||
initialBudget = 0; | ||
currentBudget = 0; | ||
} | ||
|
||
/** | ||
* Resets the current budget to initial budget. | ||
*/ | ||
public static void resetBudget() { | ||
currentBudget = initialBudget; | ||
} | ||
|
||
/** | ||
* Sets initial budget to the amount given. | ||
* | ||
* @param amount The amount to be set. | ||
*/ | ||
public static void setInitialBudget(double amount) { | ||
initialBudget = amount; | ||
} | ||
|
||
/** | ||
* Updates current budget by adding amount to current budget. | ||
* | ||
* @param amount The amount to be updated. | ||
*/ | ||
public static void updateCurrentBudget(double amount) { | ||
currentBudget += amount; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,21 @@ | |
import java.util.logging.Logger; | ||
import java.util.ArrayList; | ||
|
||
/** | ||
* Represents a command to manage the budget. | ||
*/ | ||
public class BudgetCommand extends Command { | ||
private static final Logger logger = Logger.getLogger("Financial Planner Logger"); | ||
private final Ui ui = Ui.getInstance(); | ||
private double budget; | ||
private String command; | ||
|
||
/** | ||
* Constructs a new BudgetCommand and checks if the user input is a valid command. | ||
* | ||
* @param rawCommand The raw command containing the arguments and parameters given by the user. | ||
* @throws FinancialPlannerException If there is an issue with the command provided. | ||
*/ | ||
public BudgetCommand(RawCommand rawCommand) throws FinancialPlannerException { | ||
command = rawCommand.args.get(0); | ||
if (command.equals("delete") || command.equals("reset") || command.equals("view")) { | ||
|
@@ -33,6 +42,12 @@ public BudgetCommand(RawCommand rawCommand) throws FinancialPlannerException { | |
} | ||
} | ||
|
||
/** | ||
* Checks if budget is a positive number and is lower than or equal to total balance. | ||
* | ||
* @param rawCommand The raw command containing arguments and parameters given by the user. | ||
* @throws FinancialPlannerException If there is an issue with budget format. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need javadoc for private methods also? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no |
||
private void validateBudget(RawCommand rawCommand) throws FinancialPlannerException { | ||
try { | ||
logger.log(Level.INFO, "Parsing budget as double"); | ||
|
@@ -48,10 +63,16 @@ private void validateBudget(RawCommand rawCommand) throws FinancialPlannerExcept | |
|
||
if (budget > Cashflow.getBalance()) { | ||
logger.log(Level.WARNING, "Invalid value for budget"); | ||
throw new FinancialPlannerException("Budget should be lower than total balance."); | ||
throw new FinancialPlannerException("Budget should be lower than or equal to total balance."); | ||
} | ||
} | ||
|
||
/** | ||
* Checks that the command is valid and in the right format. | ||
* | ||
* @param rawCommand The raw command containing arguments and parameters given by the user. | ||
* @throws FinancialPlannerException If there is an issue with the command or format. | ||
*/ | ||
private void validateCommandFormat(RawCommand rawCommand) throws FinancialPlannerException { | ||
if (!command.equals("set") && !command.equals("update")) { | ||
logger.log(Level.WARNING, "Invalid arguments for budget command"); | ||
|
@@ -73,6 +94,9 @@ private void validateCommandFormat(RawCommand rawCommand) throws FinancialPlanne | |
} | ||
} | ||
|
||
/** | ||
* Executes the budget command based on the specified operation. | ||
*/ | ||
@Override | ||
public void execute() { | ||
assert command.equals("set") || command.equals("update") || command.equals("delete") || | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package seedu.financialplanner.commands; | ||
|
||
/** | ||
* Represents a generic command that can be inherited. | ||
*/ | ||
public abstract class Command { | ||
public abstract void execute() throws Exception; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice addition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍