Skip to content
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

Merged
merged 8 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Developer Guide

## Table of contents

* [Acknowledgements](#acknowledgements)
* [Design & implementation](#design--implementation)
* [Storage Component](#storage-component)
* [Design considerations](#design-considerations)
* [Visualization Feature](#visualization-feature-)
* [Class diagram](#class-diagram)
* [Sequence diagram](#sequence-diagram-)
* [Add income/expense feature](#add-incomeexpense-feature)
* [Step 1](#step-1)
* [Step 2](#step-2)
* [Step 3](#step-3)
* [Step 4](#step-4)
* [Diagrams](#diagrams)
* [Budget Feature](#budget-feature)
* [Set and update budget](#set-and-update-budget)
* [Delete budget](#delete-budget)
* [Reset budget](#reset-budget)
* [View budget](#view-budget)
* [Product Scope](#product-scope)
* [Target user profile](#target-user-profile)
* [Value proposition](#value-proposition)
* [User Stories](#user-stories)
* [Non-Functional Requirements](#non-functional-requirements)
* [Glossary](#glossary)
* [Instructions for manual testing](#instructions-for-manual-testing)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice addition

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


## Acknowledgements

**Xchart (A Simple Charting Library for Java)**
Expand Down
3 changes: 1 addition & 2 deletions docs/diagrams/Budget.puml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

participant ":BudgetCommand" as BudgetCommand
participant "<<class>>\nBudget" as Budget
participant "<<class>>\nUi" as Ui
participant ":Ui" as Ui

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice


-> BudgetCommand: execute()
BudgetCommand -> Ui: getInstance()

alt set
BudgetCommand -> Budget: setBudget(budget)
Expand Down
2 changes: 1 addition & 1 deletion docs/diagrams/deleteBudget.puml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mainframe sd DeleteBudget
participant ":BudgetCommand" as BudgetCommand
participant "<<class>>\nBudget" as Budget
participant "<<class>>\nUi" as Ui
participant ":Ui" as Ui

alt hasBudget
BudgetCommand -> Budget: deleteBudget()
Expand Down
2 changes: 1 addition & 1 deletion docs/diagrams/resetBudget.puml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mainframe sd ResetBudget
participant ":BudgetCommand" as BudgetCommand
participant "<<class>>\nBudget" as Budget
participant "<<class>>\nUi" as Ui
participant ":Ui" as Ui

alt spentBudget
opt initialBudgetExceedBalance
Expand Down
2 changes: 1 addition & 1 deletion docs/diagrams/viewBudget.puml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mainframe sd ViewBudget
participant ":BudgetCommand" as BudgetCommand
participant "<<class>>\nBudget" as Budget
participant "<<class>>\nUi" as Ui
participant ":Ui" as Ui

alt hasBudget
BudgetCommand -> Ui: printBudget()
Expand Down
Binary file modified docs/images/Budget.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/deleteBudget.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/resetBudget.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/viewBudget.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/main/java/seedu/financialplanner/FinancialPlanner.java
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;
Expand All @@ -10,21 +11,35 @@

import java.time.LocalDate;

/**

Choose a reason for hiding this comment

The 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);
Expand All @@ -50,6 +65,9 @@ public void run() {
ui.exitMessage();
}

/**
* Saves existing data to the save file.
*/
public void save() {
try {
storage.save(FILE_PATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
import java.util.logging.SimpleFormatter;
import java.util.logging.LogManager;

/**
* Represents the logger for the Financial Planner.
*/
public class FinancialPlannerLogger {
private static Logger logger = Logger.getLogger("Financial Planner Logger");

/**
* Initialises the logger and saves logging info to a file.
*/
public static void initialise() {
try {
FileHandler fh = new FileHandler("data/logger.log");
Expand Down
75 changes: 74 additions & 1 deletion src/main/java/seedu/financialplanner/cashflow/Budget.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.
*/

Choose a reason for hiding this comment

The 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
import java.text.DecimalFormat;
import java.util.ArrayList;

/**
* Represents a command for displaying balance.
*/
public class BalanceCommand extends Command {
private final Ui ui = Ui.getInstance();

public BalanceCommand(RawCommand rawCommand) {
if (!rawCommand.extraArgs.isEmpty()) {
String unknownExtraArgument = new ArrayList<>(rawCommand.extraArgs.keySet()).get(0);
throw new IllegalArgumentException(String.format("Unknown extra argument: %s", unknownExtraArgument));
}
}

/**
* Executes the command to display balance.
*/
@Override
public void execute() throws Exception {
public void execute() {
ui.showMessage("Balance: " + getBalanceString());
}

Expand Down
26 changes: 25 additions & 1 deletion src/main/java/seedu/financialplanner/commands/BudgetCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -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.
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need javadoc for private methods also?

Copy link
Author

Choose a reason for hiding this comment

The 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");
Expand All @@ -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");
Expand All @@ -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") ||
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/financialplanner/commands/Command.java
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.ArrayList;

/**
* Represents a command to exit the program.
*/
public class ExitCommand extends Command {
public ExitCommand(RawCommand rawCommand) {
if (!rawCommand.extraArgs.isEmpty()) {
Expand Down
Loading