diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2511da1fda582bc1fa8753f18c8737c602c3459e..f6e9d1f9f306e76403b1f22273bc56ffc1ca1551 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -63,6 +63,7 @@ pages: script: - mvn clean package - mvn javadoc:javadoc + - mvn jacoco:prepare-agent install jacoco:report - mkdir .public - cp -rf target/site/apidocs/* .public - cp -rf target/jacoco/* .public diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/AddBudgetController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/AddBudgetController.java index de9c4872ad6e6f9facbb3ecd170004c6b9c63867..e7eb2aae1027c886300006711bcf1a063558b784 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/AddBudgetController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/AddBudgetController.java @@ -66,10 +66,20 @@ public class AddBudgetController { addEventFilters(); } + /** + * Gets the category value from the category combo box. + + * @return The category value + */ public ExpenseCategory getCategory(){ return categoryVariable.getValue(); } + /** + * Gets the newly created budget item + + * @return The budget item + */ public BudgetItem getNewBudgetItem(){ return this.newBudgetItem; } @@ -78,6 +88,7 @@ public class AddBudgetController { * Binds the item that is taken in as the argument with a budget item declared in this class. The item of this class is instantiated * as a deep copy of the argument. Each attribute of their attributes are then bounded. The text fields and category boxes * in the dialog window are then set to the values of the chosen item, as to not display empty values. + * @param item The item that is chosen to be edited. */ @FXML @@ -98,6 +109,7 @@ public class AddBudgetController { * Adds a new to the budget tableview or edits an existing entry in table if the OK button is pressed. * An entry is edited as the selected entry of the table is bounded to another budget item in this class. If this budget item * is altered, the budget item in the tableview will automatically respond with the same changes. + * @param event If the OK button is pressed. */ @FXML @@ -158,6 +170,7 @@ public class AddBudgetController { /** * Closes the dialog box. + * @param actionEvent A button click on the close button. */ @FXML diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/AddExpenseController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/AddExpenseController.java index e24143dfe1548d639e091355b668b2a2c648bd14..42ec029c439c37cd2c6e85aeb15b9b266ba92dee 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/AddExpenseController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/AddExpenseController.java @@ -24,6 +24,7 @@ import no.ntnu.idatt1002.demo.data.Economics.Expense; /** * Class that represents the popup dialog box that appears whenever an expense is to be added or edited. * The dialog contains various fields that are used to create a new expense or edit an existing expense. + * * @author Harry Linrui Xu * @since 13.3.2023 */ @@ -86,14 +87,29 @@ public class AddExpenseController { addEventFilters(); } + /** + * Gets the value of the category box. + + * @return The chosen expense category. + */ public ExpenseCategory getCategory() { return categoryBox.getValue(); } + /** + * Gets the value from the recurring box. + + * @return The chosen recurring boolean value. + */ public boolean isRecurring() { return recurringBox.getValue();//.equals("Yes"); } + /** + * Gets the newly created expense + + * @return The new expense. + */ public Expense getNewExpense() { return this.newExpense; } @@ -102,6 +118,7 @@ public class AddExpenseController { * Binds the expense that is taken in as the argument with an expense declared in this class. The expense of this class is instantiated * as a deep copy of the argument. Each attribute of their attributes are then bounded. The text fields and category boxes * in the dialog window are then set to the values of the chosen expense, as to not display empty values. + * @param expense The expense that is chosen to be edited. */ public void setExpense(Expense expense) { @@ -125,6 +142,7 @@ public class AddExpenseController { * Adds a new to the tableview or edits an existing entry in table if the OK button is pressed. * An entry is edited as the selected entry of the table is bounded to another expense in this class. If this expense * is altered, the expense in the tableview will automatically respond with the same changes. + * @param event If the OK button is pressed. */ @FXML @@ -153,6 +171,7 @@ public class AddExpenseController { /** * Closes the dialog box and cancels any pending changes. + * @param event A button click on the cancel button. */ @FXML diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/AddIncomeController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/AddIncomeController.java index 6f2d26d396cc88a015a63d46aadede7baecba960..c3981ba8828caf29993ae511f105df96b05b84aa 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/AddIncomeController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/AddIncomeController.java @@ -23,6 +23,7 @@ import no.ntnu.idatt1002.demo.data.Economics.IncomeCategory; /** * Class that represents the popup dialog box that appears whenever an income is to be added or edited. * The dialog contains various fields that are used to create a new income or edit an existing income. + * * @author Harry Linrui Xu * @since 24.3.2023 */ @@ -80,14 +81,29 @@ public class AddIncomeController { addEventFilters(); } + /** + * Gets the value of the category box. + + * @return The chosen income category. + */ public IncomeCategory getCategory() { return categoryBox.getValue(); } + /** + * Gets the value from the recurring box. + + * @return The chosen recurring boolean value. + */ public boolean isRecurring() { return recurringBox.getValue();//.equals("Yes"); } + /** + * Gets the newly created income + + * @return The new income. + */ public Income getNewIncome() { return this.newIncome; } @@ -96,11 +112,13 @@ public class AddIncomeController { * Binds the income that is taken in as the argument with an income declared in this class. The income of this class is instantiated * as a deep copy of the argument. Each attribute of their attributes are then bounded. The text fields and category boxes * in the dialog window are then set to the values of the chosen income, as to not display empty values. + * @param income The income that is chosen to be edited. */ public void setIncome(Income income) { //Deep copying income and then binding the two incomes - chosenIncome = new Income(income.getDescription(), income.getAmount(), income.isRecurring(), income.getCategory(), income.getDate()); + chosenIncome = new Income(income.getDescription(), income.getAmount(), income.isRecurring(), + income.getCategory(), income.getDate()); chosenIncome.descriptionProperty().bindBidirectional(income.descriptionProperty()); chosenIncome.amountProperty().bindBidirectional(income.amountProperty()); chosenIncome.recurringProperty().bindBidirectional(income.recurringProperty()); @@ -118,8 +136,9 @@ public class AddIncomeController { /** * Adds a new to the tableview or edits an existing entry in table if the OK button is pressed. - * An entry is edited as the selected entry of the table is bounded to another income in this class. If this income - * is altered, the income in the tableview will automatically respond with the same changes. + * An entry is edited as the selected entry of the table is bounded to another income in this class. + * If this income is altered, the income in the tableview will automatically respond with the same changes. + * @param event If the OK button is pressed. */ @FXML @@ -133,7 +152,8 @@ public class AddIncomeController { boolean recurring = isRecurring(); newIncome = new Income(description, amount, recurring, category, date); } - //Sets the value of the income(chosenIncome) that is bounded to the chosen income (not chosenIncome) in the tableview + //Sets the value of the income(chosenIncome) that is bounded to the + // chosen income (not chosenIncome) in the tableview if (chosenIncome != null) { chosenIncome.setDescription((descriptionField.getText())); chosenIncome.setAmount(Double.parseDouble(amountField.getText())); diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/AllRecipesController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/AllRecipesController.java index 80de931bafc7977a1ad8a2b5089b609d22687e4f..3c0897f44bc396ee274b6ada4a739978c239a23d 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/AllRecipesController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/AllRecipesController.java @@ -48,7 +48,7 @@ public class AllRecipesController implements Initializable { * initialize the controller once its root element has been processed. The method then reads and creates * an object of the IngredientsAtHand class and one of the RecipesRegister class. * If the recipe register exists, the list is filled with Strings for each recipe at the format: - * <Recipe name> - X missing ingredients (XX%) + * Recipe name - X missing ingredients (XX%) * Finally, a MouseClick event and handler is attached to the list that gets the recipe name of the clicked * list item and runs the method showRecipe() with that name as input to show the recipe in detail in the * view Recipe.fxml. diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/CreateBudgetController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/CreateBudgetController.java index c3e286235f7acfc41ddae62777683b7312ee664e..405bfab1a34783637ad3b17117df4b1c813bbf1d 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/CreateBudgetController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/CreateBudgetController.java @@ -28,8 +28,15 @@ public class CreateBudgetController { private String budgetName; + /** + * The ok button in the dialog window. + */ @FXML public Button okBtn; + + /** + * The cancel button in the dialog window. + */ @FXML public Button cancelBtn; diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/IngredientTileController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/IngredientTileController.java index 3762ad3c0093ab4a98c26ae67220dea0a82895e0..ea8957f4d64a2c56817134799f4953a1a1519636 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/IngredientTileController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/IngredientTileController.java @@ -20,7 +20,7 @@ public class IngredientTileController { /** * The setData method takes an RecipeIngredient object as parameter and sets the text of the label contained in * the simple pane to a formatted string following this pattern: - * "# <Ingredient name> XX.X YY" + * "# Ingredient name XX.X YY" * where XX.X is the amount of the ingredient in the recipe and YY is the unit of measure. * @param ingredient An RecipeIngredient object to format and create an Ingredient tile for. */ diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/MainMenuController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/MainMenuController.java index 46b048c9e0db845216bf77f5872fb8f967e28542..d0f49062ba3c03da5d5473eee58bdeffee87ca8c 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/MainMenuController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/MainMenuController.java @@ -128,16 +128,11 @@ public class MainMenuController { generalBudget = loadBudgetDataFromFile( "budgets/" + FileHandlingSelectedBudget .readSelectedBudget("budgets/SelectedBudget") + "/Budget"); - } catch (IOException ioe) { + overview = new Overview(incomeRegister, expenseRegister, generalBudget); + } catch (IOException | IllegalArgumentException ioe) { ioe.printStackTrace(); - Alert alert = new Alert(AlertType.ERROR); - alert.setTitle("Could not load register data"); - alert.setHeaderText("Could not load register data"); - alert.setContentText("There was an error loading in the registers"); - - alert.showAndWait(); + showErrorDialogBox(ioe.getMessage(), ioe.getMessage(), ioe.getMessage()); } - overview = new Overview(incomeRegister, expenseRegister, generalBudget); mainBar.setStyle("-fx-accent: rgb(48,215,106);"); diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/SelectBudgetController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/SelectBudgetController.java index d744fe85668aad490f789aa662ba47df0478eeaa..9bd6b1ffebdad52e93a75f7f806003c4997ae332 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/SelectBudgetController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/SelectBudgetController.java @@ -4,16 +4,21 @@ import java.io.IOException; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; +import javafx.event.Event; import javafx.fxml.FXML; import javafx.scene.Node; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListView; import javafx.scene.input.MouseButton; +import javafx.scene.input.MouseEvent; import javafx.stage.Stage; import no.ntnu.idatt1002.demo.data.Budget.BudgetRegister; import no.ntnu.idatt1002.demo.data.Budget.FileHandlingBudgetArchive; import no.ntnu.idatt1002.demo.data.Budget.FileHandlingSelectedBudget; +import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory; /** * Class for selecting a budget from the archive. @@ -34,10 +39,13 @@ public class SelectBudgetController { private BudgetRegister budgetRegister; - private ObservableList<String> budgetList; - + /** + * Initializes the view when it is loaded. Prepares the view by adding event filters, + * instantiating the budget register and setting the list view. + */ @FXML - public void initialize() throws IOException { + public void initialize() { + //Prevent users from choosing nothing okBtn.addEventFilter( ActionEvent.ACTION, event -> { if (budgetListView.getSelectionModel().getSelectedItem() == null) { @@ -46,6 +54,7 @@ public class SelectBudgetController { } }); + //Load budget register from file. try { if (FileHandlingBudgetArchive.isBudgetRegisterEmpty("budgets/Archive")) { budgetRegister = new BudgetRegister(); @@ -56,32 +65,68 @@ public class SelectBudgetController { ioe.printStackTrace(); } System.out.println("budget register is: " + budgetRegister); - budgetList = FXCollections.observableList(budgetRegister.getBudgetNames()); + ObservableList<String> budgetList = FXCollections.observableList( + budgetRegister.getBudgetNames()); budgetListView.setItems(budgetList); + //Double clicking the entry also chooses it budgetListView.setOnMouseClicked(mouseEvent-> { if(mouseEvent.getButton().equals(MouseButton.PRIMARY)){ if(mouseEvent.getClickCount() == 2){ - System.out.println("Double clicked"); + selectBudget(mouseEvent); } } }); } + /** + * Selects the budget in the budget list view and stores this value as + * the currently selected budget. + + * @param event Double mouseclick or a click on the ok button. + */ @FXML - public void selectBudget(ActionEvent event) throws IOException { - String name = budgetListView.getSelectionModel().getSelectedItem(); - FileHandlingSelectedBudget.updateSelectedBudget(name, "budgets/SelectedBudget"); + public void selectBudget(Event event) { + try { + String name = budgetListView.getSelectionModel().getSelectedItem(); + FileHandlingSelectedBudget.updateSelectedBudget(name, "budgets/SelectedBudget"); + } catch(IOException ioe) { + showErrorDialogBox(ioe.getMessage(), ioe.getMessage(), ioe.getMessage()); + } final Node source = (Node) event.getSource(); ((Stage) source.getScene().getWindow()).close(); } + /** + * Closes the dialog box and clears the currently selected budget. + + * @param event Button press on cancel button + */ @FXML - public void exitWindow(ActionEvent event) throws IOException { - FileHandlingSelectedBudget.clearSelectedBudget("budgets/SelectedBudget"); + public void exitWindow(ActionEvent event) { + try { + FileHandlingSelectedBudget.clearSelectedBudget("budgets/SelectedBudget"); + } catch (IOException ioe) { + showErrorDialogBox(ioe.getMessage(), ioe.getMessage(), ioe.getMessage()); + } final Node source = (Node) event.getSource(); ((Stage) source.getScene().getWindow()).close(); } + + /** + * Displays an error message dialog box with a customizable title, header and content. + + * @param title The dialog title. + * @param header The dialog header. + * @param content The dialog content. + */ + public void showErrorDialogBox(String title, String header, String content) { + Alert alert = new Alert(AlertType.ERROR); + alert.setTitle(title); + alert.setHeaderText(header); + alert.setContentText(content); + alert.showAndWait(); + } } diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/BudgetItem.java b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/BudgetItem.java index db057a1af3073dfbec4ffaf7986481d3bfb815e6..47518a4383168b180eebd1d6792003f870a537f0 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/BudgetItem.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/BudgetItem.java @@ -37,14 +37,23 @@ public class BudgetItem { * This method gets the BudgetAmount. * * @return the budgetAmount as a double - * */ public double getBudgetAmount() { return budgetAmount.get(); } - public DoubleProperty getAmountProperty(){ return budgetAmount;} + /** + * Gets the amount property of its corresponding amount value. + + * @return The amount property. + */ + public DoubleProperty getAmountProperty(){ return budgetAmount;} + + /** + * Sets the amount to the value of the argument. + * @param amount The value to which the amount will change. + */ public void setBudgetAmount(double amount){ this.budgetAmount.set(amount); } @@ -53,13 +62,23 @@ public class BudgetItem { * This method gets the category. * * @return the category as one of the categories in ExpenseCategory - * */ public ExpenseCategory getBudgetCategory() { return budgetCategory.get(); } + + /** + * Gets the category property of its corresponding category value. + + * @return The category property. + */ public ObjectProperty<ExpenseCategory> getCategoryProperty(){ return budgetCategory; } + /** + * Sets the budget category to the value of the argument. + + * @param category Category to which the budget item will change. + */ public void setBudgetCategory(ExpenseCategory category){ this.budgetCategory.set(category); } @@ -67,18 +86,29 @@ public class BudgetItem { /** * This method gets the description. * - * @return the description as a String - * + * @return the description as a String. */ public String getBudgetDescription() { return budgetDescription.get(); } + + /** + * Gets the description property of its corresponding description value. + + * @return The description property. + */ public StringProperty getDescriptionProperty(){ return budgetDescription; } + /** + * Sets the budget description to the value of the argument. + + * @param description Description to which the budget description will change. + */ public void setBudgetDescription(String description){ this.budgetDescription.set(description); } + @Override public String toString() { return "budgetAmount=" + getBudgetAmount() + diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/BudgetRegister.java b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/BudgetRegister.java index 7f9270a926c06dbcc9ce522c9e2cd4958797c830..3e019541ed8a9a7b39d0493e0d450e9b06f64349 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/BudgetRegister.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/BudgetRegister.java @@ -21,8 +21,14 @@ public class BudgetRegister { budgetNames = new ArrayList<>(); } + /** + * Gets a list of the budget names contained in the budget register. + + * @return Deep copied list of budget names. + */ public List<String> getBudgetNames() { - return this.budgetNames; + List<String> budgetNamesCopy = new ArrayList<>(budgetNames); + return budgetNamesCopy; } /** diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingBudgetArchive.java b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingBudgetArchive.java index 5b559c569dba441578daecbf16f6562fc3f4bcd8..3599d7092245be09c4aeaee1fb0a5ddfd5caba5f 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingBudgetArchive.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingBudgetArchive.java @@ -48,6 +48,7 @@ public class FileHandlingBudgetArchive { * Method for writing (adding) a budget register to the archive. * @param budgetNames The budget register. + * @param fileTitle The title of the file. * @throws IOException if an input or output exception occurred. */ public static void writeBudgetRegisterToArchive(BudgetRegister budgetNames, @@ -64,6 +65,7 @@ public class FileHandlingBudgetArchive { * Checks if the budget register in the archive contains any budget names. * In other words, if it is empty. + * @param fileTitle title of the file. * @return True, if only "null" is read. Else, returns false. * @throws IOException if an input or output exception occurred. */ @@ -110,7 +112,7 @@ public class FileHandlingBudgetArchive { * that should be removed should have their directory deleted. * @param budgetId The name of the budget directory that holds all the data - * for a given budget. + * for a given budget. * @return True, if the directory is successfully deleted. Else, returns false. */ public static boolean deleteBudgetDirectory(String budgetId) { diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingSelectedBudget.java b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingSelectedBudget.java index 20b1ea92724b1ddcfd0760645631f2bf3d114e05..9a0b065c4de4c212887f53eed62566d2fea93e72 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingSelectedBudget.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingSelectedBudget.java @@ -25,6 +25,7 @@ public class FileHandlingSelectedBudget { /** * Reads the name of the currently selected budget. + * @param fileTitle The title of the file. * @return A string of the budget name. * @throws IOException if an input or output exception occurred. */ @@ -42,7 +43,9 @@ public class FileHandlingSelectedBudget { /** * Writes the currently used budget name to file, essentially updating the * file. + * @param budgetName The name of the budget. + * @param fileTitle Title of the file. * @throws IOException if an input or output exception occurred. */ public static void updateSelectedBudget(String budgetName, String fileTitle) throws IOException { @@ -61,6 +64,7 @@ public class FileHandlingSelectedBudget { * Clears the entire file that holds the current budget. In case a budget is deleted, * this method prevents the file of containing a budget name that no longer exists. + * @param fileTitle The title of the file. * @throws IOException if an input or output exception occurred. */ public static void clearSelectedBudget(String fileTitle) throws IOException { diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/GeneralBudget.java b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/GeneralBudget.java index ba766c728e10273905047e7198a6ba27edbbcaaa..d7f1577a2286dabfd41e205c2297356892641aa0 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/GeneralBudget.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/GeneralBudget.java @@ -34,7 +34,14 @@ public class GeneralBudget { */ private final Savings savings; + /** + * Constructor for a general budget, which is an entire budget project, set + * for a given month. + * @param budgetItems List of the budget items in the project. + * @param maxAmount Money at disposable to allocate. + * @param savings Unused money from last month. + */ public GeneralBudget(List<BudgetItem> budgetItems, double maxAmount, Savings savings) { if (maxAmount < 0) { throw new IllegalArgumentException("The max amount of the budget cant be less than zero"); @@ -101,7 +108,7 @@ public class GeneralBudget { * Method for getting budgetItems * * @return an ArrayList of every BudgetItem - * @throws if budgetItems is empty + * @throws IllegalArgumentException if budgetItems is empty */ public List<BudgetItem> getBudgetItems() throws IllegalArgumentException { return budgetItems; diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/MMBI.java b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/MMBI.java index 291d1651df7edc005f7d6b99bf8def575b3072d0..fe15c58322935001fb04b138acc63af1adc08dd4 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/MMBI.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/MMBI.java @@ -2,27 +2,61 @@ package no.ntnu.idatt1002.demo.data.Budget; import javafx.scene.control.ProgressBar; +/** + * Class that represents the main menu category progress bars. Each bar + * is associated with a corresponding expense category. + * + * @author Anders Emil Bergan. + * @since 17.04.2023. + */ public class MMBI { private ProgressBar progressBar; private BudgetItem budgetItem; + /** + * Constructor for creating a MMBI. + + * @param item The budget item. + * @param bar The progress bar. + */ public MMBI(BudgetItem item, ProgressBar bar){ this.budgetItem = item; this.progressBar = bar; } + /** + * Gets the budget item. + + * @return the budget item. + */ public BudgetItem getBudgetItem(){ return budgetItem; } + /** + * Sets the budget item to the argument value. + + * @param item The value to which the budget item will be set. + */ public void setBudgetItem(BudgetItem item){ this.budgetItem = item; } + + /** + * Gets the progress bar. + + * @return the progress bar. + */ public ProgressBar getBar(){ return progressBar; } + /** + * Sets the progress bar to the argument value. + + * @param bar The value to which the progress bar will be set. + */ public void setProgressBar(ProgressBar bar){ this.progressBar = bar; } diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/Savings.java b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/Savings.java index 2bd4d4762f390161139456280fc8933b7b66c9d3..a16a25a5da0280208a645b0cdc0735d6af298493 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/Savings.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/Savings.java @@ -58,7 +58,7 @@ public class Savings { * amount to a given double. * * @param savingsGoals the ArrayList you want to assign savingsGoals - * @param amount + * @param amount The amount of the saving. */ public Savings(ArrayList<SavingsGoal> savingsGoals, double amount) { this.savingsGoals = savingsGoals; diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Economics/Expense.java b/src/main/java/no/ntnu/idatt1002/demo/data/Economics/Expense.java index de47509b32c5ee29e911f21e4007236a16cbeae0..a1253e1d5f60d3bf5f2a4a9511eea0f0db092ef6 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Economics/Expense.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Economics/Expense.java @@ -6,8 +6,17 @@ import javafx.beans.property.SimpleObjectProperty; import java.time.LocalDate; import java.util.Objects; +/** + * This class represents an expense. An expense is an object consisting of four mandatory + * parameters being its amount, whether it is recurring, a category, a date it was created + * and the optional description. Expense inherits from the abstract Item class where the + * category parameter is unique. + * + * @author Hanne-Sofie Søreide + * @since 05.03.2023 + */ public class Expense extends Item{ - private ObjectProperty<ExpenseCategory> category; + private final ObjectProperty<ExpenseCategory> category; /** * This constructor uses the super constructor to set the fields for 'amount' and 'recurring' and then sets the @@ -45,6 +54,11 @@ public class Expense extends Item{ this.category = new SimpleObjectProperty<>(category); } + /** + * Gets an Object Property of the Expense Category. + + * @return Expense Category property. + */ public ObjectProperty<ExpenseCategory> expenseCategoryObjectProperty() { return this.category; } diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Economics/ExpenseCategory.java b/src/main/java/no/ntnu/idatt1002/demo/data/Economics/ExpenseCategory.java index 4a94a25690394e97fc1eabcf4ba2654194fa453c..54b445d15a8fe25071798bfd7afe4e2836ed65c6 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Economics/ExpenseCategory.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Economics/ExpenseCategory.java @@ -1,18 +1,61 @@ package no.ntnu.idatt1002.demo.data.Economics; +/** + * This class represents various types of expenditures that a user can choose from. + * While not covering every kind of expense they give a good range to work with. + * + * @author Andreas Kluge Svensrud. + * @since 02.03.2023. + */ public enum ExpenseCategory { + /** + * Expenditures on food, such as groceries. + */ FOOD("food"), + + /** + * Expenditures on rent. + */ RENT("rent"), + + /** + * Expenditures on clothes. + */ CLOTHES("clothes"), + + /** + * Expenditures on books. + */ BOOKS("books"), + + /** + * Expenditures on health. + */ HEALTH("health"), + + /** + * Expenditures on activities, such as a bowling night. + */ ACTIVITIES("activities"), - OTHER("other"); + /** + * Expenditures on everything not listed above. + */ + OTHER("other"); + /** + * Label of the categories. The label formats + * the string value of the categories two string in lower caps. + */ public final String label; + /** + * The constructor of the enum constants takes in a string label and assigns + * it to its respective constant. + * The label is used for representation in texts and lists at the frontend of the application. + * @param label A lower-case and readable string representation of the enum constant. + */ ExpenseCategory(String label) { this.label = label; } diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Economics/FileHandling.java b/src/main/java/no/ntnu/idatt1002/demo/data/Economics/FileHandling.java index 6051903b7869156dc163890f8bcd6bdffaa5788f..78391f84fa2994c20ca3aaa401eebf9b473acff5 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Economics/FileHandling.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Economics/FileHandling.java @@ -25,10 +25,12 @@ public class FileHandling{ /** * Method for writing (adding) an ItemRegister to a file. * + * @param <T> Subclass of item, either expense or income. * @param itemRegister the ItemRegister you want to write to a file. * @param fileTitle the name of the file you want to check * @throws IOException if an input or output exception occurred. */ + public static <T extends Item>void writeItemRegisterToFile(final ItemRegister<T> itemRegister, String fileTitle) throws IOException { try (BufferedWriter bw = new BufferedWriter(new FileWriter(filePath + fileTitle + fileType))) { if (itemRegister.isEmpty()){ diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Economics/Income.java b/src/main/java/no/ntnu/idatt1002/demo/data/Economics/Income.java index 4b8eaae921444b441cc45821ec7a0209fa69d360..6eaf54f91ca792e9c2cb37de96bd34c8e55071c5 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Economics/Income.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Economics/Income.java @@ -38,6 +38,7 @@ public class Income extends Item{ /** * This constructor uses the super constructor to set the fields for 'amount', 'description' and 'recurring' * and then sets the category. A IllegalArgumentException from this constructor if the category is left blank. + * @param description A description of the income as a String. * @param amount The amount of the current income object as a double. * @param recurring True if the current income repeats at regular intervals. @@ -53,6 +54,11 @@ public class Income extends Item{ } + /** + * Gets the ObjectProperty of the category value. + + * @return The property of the income category. + */ public ObjectProperty<IncomeCategory> incomeCategoryObjectProperty() { return this.category; } diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Economics/IncomeCategory.java b/src/main/java/no/ntnu/idatt1002/demo/data/Economics/IncomeCategory.java index 5c5ce82c812b64482def698c439beed1e7f0c34b..7338c3602b52286e8de2d39c986dda0b6a7ad02c 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Economics/IncomeCategory.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Economics/IncomeCategory.java @@ -1,12 +1,41 @@ package no.ntnu.idatt1002.demo.data.Economics; +/** + * This class represents various types of income that a user can choose from. + * While not covering every kind of income they give a good range to work with. + * + * @author HanneSofie + * @since 05.03.2023. + */ public enum IncomeCategory { + + /** + * The monthly salary of the user. + */ SALARY("salary"), + + /** + * The monthly amount the user receives in student loan. + */ STUDENT_LOAN("student loan"), + + /** + * Monetary gifts. + */ GIFT("gift"); + /** + * Label of the categories. The label formats + * the string value of the categories two string in lower caps. + */ public final String label; + /** + * The constructor of the enum constants takes in a string label and assigns it to + * its respective constant. + * The label is used for representation in texts and lists at the frontend of the application. + * @param label A lower-case and readable string representation of the enum constant. + */ IncomeCategory(String label) { this.label = label; } diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Economics/Item.java b/src/main/java/no/ntnu/idatt1002/demo/data/Economics/Item.java index 57c2a8f77081a8fd391ed66ed461c978ae5475cb..b6737f7489d4b3ba1c7640de980585ec1daffc24 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Economics/Item.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Economics/Item.java @@ -7,21 +7,41 @@ import javafx.beans.property.*; /** * The Item class represents a good or service purchased in real life. The item belongs to a category and - * has an amount, description and a date. The description may be left blank, but the Item must belong to a category and must - * have a price. - * @author HanneSofie + * has an amount, description and a date. The description may be left blank, + * but the Item must belong to a category and must have a price. * + * @author HanneSofie + * @since 02.03.2023 */ public abstract class Item { + + /** + * String property for description. Allows for binding. + */ private StringProperty description = new SimpleStringProperty(""); + + /** + * Double property for amount. Allows for binding. + */ private final DoubleProperty amount; - private BooleanProperty recurring; - private ObjectProperty<LocalDate> date; // Format example: 09.08.23 + + /** + * Boolean property for recurring. Allows for binding. + */ + private final BooleanProperty recurring; + + /** + * ObjectProperty property for date. Allows for binding. + */ + private final ObjectProperty<LocalDate> date; // Format example: 09.08.23 /** * The constructor of a new Item object takes in an amount as a double. If the amount is left blank, an * IllegalArgumentException is thrown. + * @param amount price of an Item as a float. + * @param recurring Value informing if the item is recurring or not. + * @param date The date the item is created. */ public Item (double amount, boolean recurring, LocalDate date){ if(amount <= 1.0f || date.toString().isBlank()) { @@ -37,17 +57,26 @@ public abstract class Item { * The constructor instantiates a new Item object with a category, a description and a price as arguments. It * overloads the first constructor to set the category and price and then sets the description of the item. * If either 0category or price is left blank, an IllegalArgumentException is thrown. + * @param description A description of the item as a String. * @param amount The price of the item as a float. + * @param recurring Value informing if the item is recurring or not. + * @param date The date the item is created.* */ public Item (String description, double amount, boolean recurring, LocalDate date){ this(amount, recurring, date); this.description = new SimpleStringProperty(description); } + /** + * Gets the String Property of the description. + + * @return String property of description. + */ public StringProperty descriptionProperty() { return this.description; } + /** * The method returns the description of the given Item object as a String. * @return The description of the Item as a String. @@ -65,6 +94,11 @@ public abstract class Item { this.description.set(description); } + /** + * Gets the Double Property of the amount. + + * @return Double Property of amount. + */ public DoubleProperty amountProperty() { return this.amount; } @@ -114,7 +148,7 @@ public abstract class Item { /** * The method returns the ObjectProperty of date. - * @return + * @return The date property. */ public ObjectProperty<LocalDate> dateProperty() { return this.date; diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/recipes/FileHandler.java b/src/main/java/no/ntnu/idatt1002/demo/data/recipes/FileHandler.java index 88f4251800d886fd008c7c11682110a348bfc85e..958aec7693c2903596b52f28c6990256adeec685 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/recipes/FileHandler.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/recipes/FileHandler.java @@ -172,6 +172,7 @@ public class FileHandler { * @param ingredientsAtHand An IngredientsAtHand object that holds a collection of constants of the * FoodItem enum class. * @param title The title by which to name the file that the ingredients at hand are written to. + * @throws IOException if an input or output error occurs. */ public static void writeIngredientsAtHand(IngredientsAtHand ingredientsAtHand, String title) throws IOException { StringBuilder sb = new StringBuilder(); diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/recipes/FoodItem.java b/src/main/java/no/ntnu/idatt1002/demo/data/recipes/FoodItem.java index 8dfa3710b2945177d353b71dcce3a34c22645d71..94c1696f841b361237b67e790347d9448b8857e3 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/recipes/FoodItem.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/recipes/FoodItem.java @@ -7,77 +7,334 @@ package no.ntnu.idatt1002.demo.data.recipes; * to represent each enum value. * * @author hannesofie + * @since 13.03.2023 */ public enum FoodItem { + /** + * Onion + */ ONION("onion"), + + /** + * Minced meat. + */ MINCED_MEAT("minced meat"), + + /** + * Potato. + */ POTATO("potato"), + + /** + * Yellow cheese. + */ YELLOW_CHEESE("yellow cheese"), + + /** + * Wheat flour. + */ WHEAT_FLOUR("wheat flour"), + + /** + * Milk. + */ MILK("milk"), + + /** + * Tomato. + */ TOMATO("tomato"), + + /** + * Orange. + */ ORANGE("orange"), + + /** + * Lemon. + */ LEMON("lemon"), + + /** + * Salsa sauce. + */ SALSA_SAUCE("salsa sauce"), + + /** + * Cucumber. + */ CUCUMBER("cucumber"), + + /** + * Salad. + */ SALAD("salad"), + + /** + * Spinach. + */ SPINACH("spinach"), + + /** + * Spring roll. + */ SPRING_ROLL("spring roll"), + + /** + * Bell pepper. + */ BELL_PEPPER("bell pepper"), + + /** + * Chickpeas. + */ CHICKPEAS("chickpeas"), + + /** + * Spaghetti. + */ SPAGHETTI("spaghetti"), + + /** + * Pasta. + */ PASTA("pasta"), + + /** + * Cream. + */ CREAM("cream"), + + /** + * Honey. + */ HONEY("honey"), + + /** + * Vinegar. + */ VINEGAR("vinegar"), + + /** + * Tomato paste. + */ TOMATO_PASTE("tomato paste"), + + /** + * Chili. + */ CHILLI("chilli"), + + /** + * Egg. + */ EGG("egg"), + + /** + * Olive oil. + */ OLIVE_OIL("olive oil"), + + /** + * Ham. + */ HAM("ham"), + + /** + * Parmesan. + */ PARMESAN("parmesan"), + + /** + * Snap pea. + */ SNAP_PEA("snap pea"), + + /** + * Macaroni. + */ MACARONI("macaroni"), + + /** + * Salmon. + */ SALMON("salmon"), + + /** + * Fish. + */ FISH("fish"), + + /** + * Carrot. + */ CARROT("carrot"), + + /** + * Butter. + */ BUTTER("butter"), + + /** + * Leek. + */ LEEK("leek"), + + /** + * Bread crumbs. + */ BREADCRUMBS("breadcrumbs"), + + /** + * Oil. + */ OIL("oil"), + + /** + * Summer cutlet. + */ SUMMER_CUTLET("summer cutlet"), + + /** + * Red onion. + */ RED_ONION("red onion"), + + /** + * Avocado. + */ AVOCADO("avocado"), + + /** + * Lemon juice. + */ LEMON_JUICE("lemon juice"), + + /** + * Dry thyme. + */ DRY_THYME("dry thyme"), + + /** + * Fresh yeast. + */ FRESH_YEAST("fresh yeast"), + + /** + * Garlic clove. + */ GARLIC_CLOVE("garlic clove"), + + /** + * Ginger. + */ GINGER("ginger"), + + /** + * Canned tomato. + */ CANNED_TOMATO("canned tomato"), + + /** + * Dry basil. + */ DRY_BASIL("dry basil"), + + /** + * Fresh basil. + */ FRESH_BASIL("fresh basil"), + + /** + * Celery. + */ CELERY("celery"), + + /** + * Broth. + */ BROTH("broth"), + + /** + * Bay leaf. + */ BAY_LEAF("bay leaf"), + + /** + * Chili beans. + */ CHILLI_BEANS("chilli beans"), + + /** + * Chili powder. + */ CHILLI_POWDER("chilli powder"), + + /** + * Cumin powder. + */ CUMIN_POWDER("cumin powder"), + + /** + * Pie dough. + */ PIE_DOUGH("pie dough"), + + /** + * Broccoli. + */ BROCCOLI("broccoli"), + + /** + * Lam + */ LAM("lam"), + + /** + * Sugar. + */ SUGAR("sugar"), + + /** + * Shallot. + */ SHALLOT("shallot"), + + /** + * Red wine. + */ RED_WINE("red wine"), + + /** + * White bananas. + */ WHITE_BEANS("white beans"), + + /** + * Frozen green peas + */ FROZEN_GREEN_PEAS("frozen green peas"), + + /** + * Sausage. + */ SAUSAGE("sausage"), + + /** + * Dry oregano + */ DRY_OREGANO("dry oregano"); + /** + * Label of the categories. The label formats + * the string value of the categories two string in lower caps. + */ public final String label; /** - * The constructor of the enum constants takes in a string label and assigns it to its respective constant. + * The constructor of the enum constants takes in a string label and + * assigns it to its respective constant. * The label is used for representation in texts and lists at the frontend of the application. * @param label A lower-case and readable string representation of the enum constant. */ diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/recipes/MeasuringUnit.java b/src/main/java/no/ntnu/idatt1002/demo/data/recipes/MeasuringUnit.java index 5f0165adde0f6bc15cd79a5580679b0cc4e035a5..d1d53182bbc63cc7a09537e73894a313c6b07336 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/recipes/MeasuringUnit.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/recipes/MeasuringUnit.java @@ -6,22 +6,70 @@ package no.ntnu.idatt1002.demo.data.recipes; * presentation to the user. * * @author hannesofie + * @since 13.03.2023 */ public enum MeasuringUnit { + /** + * Deciliter. + */ DL("dl."), + + /** + * Liter. + */ L("l."), + + /** + * Teaspoon. + */ TSP("tsp."), + + /** + * Tablespoon. + */ TBS("tbs."), + + /** + * Gram. + */ GR("gr."), + + /** + * Kilogram + */ KG("kg."), + + /** + * Pieces. + */ PC("pieces"), + + /** + * Can. + */ CAN("can"), + + /** + * Slice + */ SLICE("slice"), + + /** + * Pack + */ PKG("pack"), + + /** + * Cubes. + */ CB("cubes"); + /** + * Label of the categories. The label formats + * the string value of the categories two string in lower caps. + */ public final String label; /** diff --git a/src/main/java/no/ntnu/idatt1002/demo/view/App.java b/src/main/java/no/ntnu/idatt1002/demo/view/App.java index 91586aac95fe94e6f494429e275f87f11130f5c3..bf128295effb615ad4cc4da9ad90905290d30b75 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/view/App.java +++ b/src/main/java/no/ntnu/idatt1002/demo/view/App.java @@ -1,6 +1,18 @@ package no.ntnu.idatt1002.demo.view; +/** + * The class from which the main application is caleld upon. + * + * @author Harry Linrui Xu + * @since 11.03.2023 + */ public class App { + + /** + * The main method that calls on the MyApp class + + * @param args String of arguments + */ public static void main(String[] args) { MyApp.main(args); } diff --git a/src/main/java/no/ntnu/idatt1002/demo/view/MyApp.java b/src/main/java/no/ntnu/idatt1002/demo/view/MyApp.java index 148b88524acd9271e95344e4c9c33dcd5a253981..c274fd98c00ae1d6ff5a073088fdae4a77a09512 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/view/MyApp.java +++ b/src/main/java/no/ntnu/idatt1002/demo/view/MyApp.java @@ -8,8 +8,18 @@ import javafx.scene.Scene; import java.io.IOException; +/** + * This is the class that the main application is run from. When a user decides to + * run the application, this class calls on the start method which starts the application. + */ public class MyApp extends Application { + /** + * The start method which is where the application is opened. + + * @param stage The stage or window at which the GUI is displayed. + * @throws IOException If an occurs loading the first view. + */ @Override public void start(Stage stage) throws IOException { FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/FirstMenu.fxml")); @@ -19,7 +29,11 @@ public class MyApp extends Application { stage.show(); } - public static void main(String[] args) { + /** + * The main method that calls on the start method. + * @param args String of arguments. + */ + public static void main(String[] args) { launch(args); } } diff --git a/src/main/java/no/ntnu/idatt1002/demo/view/NewBudget.java b/src/main/java/no/ntnu/idatt1002/demo/view/NewBudget.java deleted file mode 100644 index 2844313e33642897ff58d598a5b62e2e162c073d..0000000000000000000000000000000000000000 --- a/src/main/java/no/ntnu/idatt1002/demo/view/NewBudget.java +++ /dev/null @@ -1,42 +0,0 @@ -package no.ntnu.idatt1002.demo.view; - -import javafx.geometry.Insets; -import javafx.geometry.Pos; -import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.control.TextArea; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; -import javafx.scene.layout.HBox; -import javafx.scene.layout.Pane; -import javafx.scene.layout.StackPane; -import javafx.scene.layout.VBox; -import javafx.scene.text.Font; -import javafx.scene.text.FontPosture; -import javafx.scene.text.FontWeight; -import javafx.stage.Stage; - -import java.io.FileInputStream; -import java.io.IOException; - -public class NewBudget { - - private static StackPane root; - public static Pane getRoot() throws IOException { - - TextArea income = new TextArea(); - TextArea income2 = new TextArea(); - income.setMaxSize(200, 20); - income2.setMaxSize(200, 20); - VBox inputs = new VBox(); - inputs.getChildren().addAll(income, income2); - inputs.setAlignment(Pos.CENTER); - inputs.setSpacing(100); - - - return root; - } - -} - diff --git a/src/main/resources/budgets/Archive.archive b/src/main/resources/budgets/Archive.archive index 415bab20c3fe4b8bf68d40fed7fd72f6b4e0620c..92bbadc75e7a0d12ca16ffa702c311280f70242c 100644 --- a/src/main/resources/budgets/Archive.archive +++ b/src/main/resources/budgets/Archive.archive @@ -1,4 +1 @@ -APRILnew -APRILsecond -APRILreasonable -APRILpåske +APRILels diff --git a/src/main/resources/budgets/SelectedBudget.current b/src/main/resources/budgets/SelectedBudget.current index 5d60f791060cd30d347b32fc1ff332ce182e0c55..160765175f94b330face63124bef8d27303d181c 100644 --- a/src/main/resources/budgets/SelectedBudget.current +++ b/src/main/resources/budgets/SelectedBudget.current @@ -1 +1 @@ -APRILreasonable +APRILels \ No newline at end of file