Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • team13/tdat1006
  • eivindrt/tdat1006
  • alexholt/idatt1002
  • elinang/idatt1002
  • surya/idatt1002
  • kjellit/idata-1002-demo-project
  • eskillr/idatt1002
  • G1-06/idatt-1002-2022-1-06
  • emillaa/idatt1002
  • andreksv/idatt-1002-2023-9
  • melane/idatt-1002-2023-5
  • ramtinfs/idatt1002
  • surya/idatx1005
  • itatt1005_2024_group15/purchase-planner
  • systemutvikling-gruppe-19/idatt-1005-2024-group-19
15 results
Show changes
Commits on Source (192)
Showing
with 1413 additions and 64 deletions
############################## ##############################
## Java ## Java
############################## ##############################
.mtj.tmp/ .mtj.tmp/
*.class *.class
*.jar *.jar
*.war *.war
*.ear *.ear
*.nar *.nar
############################## ##############################
## Maven ## Maven
############################## ##############################
target/ target/
pom.xml.tag pom.xml.tag
pom.xml.releaseBackup pom.xml.releaseBackup
pom.xml.versionsBackup pom.xml.versionsBackup
pom.xml.next pom.xml.next
pom.xml.bak pom.xml.bak
release.properties release.properties
dependency-reduced-pom.xml dependency-reduced-pom.xml
buildNumber.properties buildNumber.properties
.mvn/timing.properties .mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar .mvn/wrapper/maven-wrapper.jar
############################## ##############################
## IntelliJ ## IntelliJ
############################## ##############################
out/ out/
.idea/* .idea/*
*.iml *.iml
*.ipr *.ipr
*.iws *.iws
############################## ##############################
## Database ## Database
############################## ##############################
*.db *.db
*.DS_Store *.DS_Store
...@@ -88,7 +88,7 @@ loadScripts(document, 'script');</script> ...@@ -88,7 +88,7 @@ loadScripts(document, 'script');</script>
<h1 title="Class MyApp" class="title">Class MyApp</h1> <h1 title="Class MyApp" class="title">Class MyApp</h1>
</div> </div>
<div class="inheritance" title="Inheritance Tree"><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">java.lang.Object</a> <div class="inheritance" title="Inheritance Tree"><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">java.lang.Object</a>
<div class="inheritance">no.ntnu.idatt1002.demo.MyApp</div> <div class="inheritance">no.ntnu.idatt1002.demo.view.MyApp</div>
</div> </div>
<section class="class-description" id="class-description"> <section class="class-description" id="class-description">
<hr> <hr>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<!-- Generated by javadoc (19) on Thu Feb 02 10:19:17 CET 2023 --> <!-- Generated by javadoc (19) on Thu Feb 02 10:19:17 CET 2023 -->
<title>Uses of Class no.ntnu.idatt1002.demo.MyApp (demo 1.0-SNAPSHOT API)</title> <title>Uses of Class no.ntnu.idatt1002.demo.view.MyApp (demo 1.0-SNAPSHOT API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2023-02-02"> <meta name="dc.created" content="2023-02-02">
...@@ -50,9 +50,9 @@ loadScripts(document, 'script');</script> ...@@ -50,9 +50,9 @@ loadScripts(document, 'script');</script>
<div class="flex-content"> <div class="flex-content">
<main role="main"> <main role="main">
<div class="header"> <div class="header">
<h1 title="Uses of Class no.ntnu.idatt1002.demo.MyApp" class="title">Uses of Class<br>no.ntnu.idatt1002.demo.MyApp</h1> <h1 title="Uses of Class no.ntnu.idatt1002.demo.view.MyApp" class="title">Uses of Class<br>no.ntnu.idatt1002.demo.view.MyApp</h1>
</div> </div>
No usage of no.ntnu.idatt1002.demo.MyApp</main> No usage of no.ntnu.idatt1002.demo.view.MyApp</main>
<footer role="contentinfo"> <footer role="contentinfo">
<hr> <hr>
<p class="legal-copy"><small>Copyright &#169; 2023. All rights reserved.</small></p> <p class="legal-copy"><small>Copyright &#169; 2023. All rights reserved.</small></p>
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<maven.compiler.target>17</maven.compiler.target> <maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.8.1</junit.version> <junit.version>5.8.1</junit.version>
<javafx.version>17.0.1</javafx.version> <javafx.version>19.0.2.1</javafx.version>
</properties> </properties>
<repositories> <repositories>
...@@ -152,7 +152,7 @@ ...@@ -152,7 +152,7 @@
<archive> <archive>
<manifest> <manifest>
<mainClass> <mainClass>
no.ntnu.idatt1002.demo.MyApp no.ntnu.idatt1002.demo.view.MyApp
</mainClass> </mainClass>
</manifest> </manifest>
</archive> </archive>
...@@ -172,7 +172,7 @@ ...@@ -172,7 +172,7 @@
<!-- Default configuration for running with: mvn clean javafx:run --> <!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id> <id>default-cli</id>
<configuration> <configuration>
<mainClass>no.ntnu.idatt1002.demo/no.ntnu.idatt1002.demo.MyApp</mainClass> <mainClass>no.ntnu.idatt1002.demo.view.MyApp</mainClass>
<launcher>app</launcher> <launcher>app</launcher>
<jlinkZipName>app</jlinkZipName> <jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName> <jlinkImageName>app</jlinkImageName>
......
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CheckStyle-IDEA" serialisationVersion="2">
<checkstyleVersion>10.6.0</checkstyleVersion>
<scanScope>JavaOnly</scanScope>
<option name="thirdPartyClasspath" />
<option name="activeLocationIds" />
<option name="locations">
<list>
<ConfigurationLocation id="bundled-sun-checks" type="BUNDLED" scope="All" description="Sun Checks">(bundled)</ConfigurationLocation>
<ConfigurationLocation id="bundled-google-checks" type="BUNDLED" scope="All" description="Google Checks">(bundled)</ConfigurationLocation>
</list>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/main/main.iml" filepath="$PROJECT_DIR$/main/main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/src.iml" filepath="$PROJECT_DIR$/.idea/src.iml" />
<module fileurl="file://$PROJECT_DIR$/test/test.iml" filepath="$PROJECT_DIR$/test/test.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
package no.ntnu.idatt1002.demo;
import no.ntnu.idatt1002.demo.view.MyWindow;
/**
* Use this class to start the application
* @author nilstes
*/
public class MyApp {
/**
* Main method for my application
*/
public static void main(String[] args) throws Exception {
MyWindow window = new MyWindow("The Window");
window.setVisible(true);
}
}
package no.ntnu.idatt1002.demo.controller;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import no.ntnu.idatt1002.demo.data.Budget.BudgetItem;
import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory;
public class AddBudgetController {
BudgetItem newBudgetItem = null;
BudgetItem chosenBudgetItem = null;
@FXML
private ComboBox<ExpenseCategory> categoryVariable;
@FXML
private TextField amountVariable;
@FXML
private TextField descriptionVariable;
@FXML
private Button addButton;
@FXML
private Button cancelButton;
@FXML
public void initialize(){
ObservableList<ExpenseCategory> expenseCategories = FXCollections.observableArrayList(
ExpenseCategory.values());
categoryVariable.setItems(expenseCategories);
categoryVariable.setPromptText("Category");
}
public ExpenseCategory getCategory(){
return categoryVariable.getValue();
}
public BudgetItem getNewBudgetItem(){
return this.newBudgetItem;
}
@FXML
public void addBudget(ActionEvent event) {
if(newBudgetItem == null){
ExpenseCategory category = getCategory();
double amount = Double.parseDouble(amountVariable.getText());
String description = descriptionVariable.getText();
newBudgetItem = new BudgetItem(amount, description, category);
}
if(chosenBudgetItem != null){
chosenBudgetItem.setBudgetAmount(Double.parseDouble(amountVariable.getText()));
chosenBudgetItem.setBudgetDescription(descriptionVariable.getText());
chosenBudgetItem.setBudgetCategory(categoryVariable.getValue());
}
final Node source = (Node) event.getSource();
final Stage stage = (Stage) source.getScene().getWindow();
stage.close();
}
@FXML
public void setBudget(BudgetItem item){
chosenBudgetItem = new BudgetItem(item.getBudgetAmount(), item.getBudgetDescription(), item.getBudgetCategory());
chosenBudgetItem.getAmountProperty().bindBidirectional(item.getAmountProperty());
chosenBudgetItem.getDescriptionProperty().bindBidirectional(item.getDescriptionProperty());
chosenBudgetItem.getCategoryProperty().bindBidirectional(item.getCategoryProperty());
amountVariable.textProperty().set(String.valueOf(item.getBudgetAmount()));
descriptionVariable.textProperty().set(item.getBudgetDescription());
categoryVariable.setValue(item.getBudgetCategory());
}
public void closeButton(ActionEvent actionEvent) {
final Node source = (Node) actionEvent.getSource();
final Stage stage = (Stage) source.getScene().getWindow();
stage.close();
}
}
package no.ntnu.idatt1002.demo.controller;
import java.text.NumberFormat;
import java.time.LocalDate;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import no.ntnu.idatt1002.demo.data.Economics.Expense;
import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory;
import no.ntnu.idatt1002.demo.data.Economics.Income;
public class AddExpenseController {
Expense newExpense = null; //the expense that is chosen when editing or the expense that is created when adding
Expense chosenExpense = null; //an expense that is meant to track the old state of an expense before editing, in case cancel bugtton is clicked
@FXML
private Button cancelBtn;
@FXML
private Button okBtn;
@FXML
private TextField dateField;
@FXML
private DatePicker datePicker;
@FXML
private TextField descriptionField;
@FXML
private TextField amountField;
@FXML
private ComboBox<ExpenseCategory> categoryBox;
@FXML
private ComboBox<Boolean> recurringBox;
@FXML
public void initialize() {
ObservableList<ExpenseCategory> expenseCategories = FXCollections.observableArrayList(
ExpenseCategory.values());
categoryBox.setItems(expenseCategories);
categoryBox.setValue(ExpenseCategory.FOOD);
ObservableList<Boolean> recurring = FXCollections.observableArrayList(true, false);
recurringBox.setItems(recurring);
recurringBox.setValue(false);
datePicker.setValue(LocalDate.now());
}
public ExpenseCategory getCategory() {
return categoryBox.getValue();
}
public boolean isRecurring() {
return recurringBox.getValue();//.equals("Yes");
}
public void setExpense(Expense expense) { //TODO NEED CANCEL BUTTON TO REMOVE THE CHANGES IF CANCEL IS PRESSED
chosenExpense = new Expense(expense.getDescription(), expense.getAmount(), expense.isRecurring(), expense.getCategory(), expense.getDate());
chosenExpense.descriptionProperty().bindBidirectional(expense.descriptionProperty());
chosenExpense.amountProperty().bindBidirectional(expense.amountProperty());
chosenExpense.recurringProperty().bindBidirectional(expense.recurringProperty());
chosenExpense.expenseCategoryObjectProperty().bindBidirectional(expense.expenseCategoryObjectProperty());
chosenExpense.dateProperty().bindBidirectional(expense.dateProperty());
descriptionField.textProperty().set(expense.getDescription());
amountField.textProperty().setValue(String.valueOf(expense.getAmount()));
recurringBox.setValue(expense.isRecurring());
datePicker.setValue(expense.getDate());
categoryBox.setValue(expense.getCategory());
}
@FXML
public void pressOkBtn(ActionEvent event) {
if (newExpense == null) {
LocalDate date = datePicker.getValue();
double amount = Double.parseDouble(amountField.getText());
String description = descriptionField.getText();
ExpenseCategory category = getCategory();
boolean recurring = isRecurring();
newExpense = new Expense(description, amount, recurring, category, date);
}
if (chosenExpense != null) {
chosenExpense.setDescription((descriptionField.getText()));
chosenExpense.setAmount(Double.parseDouble(amountField.getText()));
chosenExpense.setRecurring(recurringBox.getValue());
chosenExpense.setCategory(categoryBox.getValue());
chosenExpense.setDate(datePicker.getValue());
}
final Node source = (Node) event.getSource();
((Stage) source.getScene().getWindow()).close();
}
@FXML
public void pressCancelBtn(ActionEvent event) {
final Node source = (Node) event.getSource();
final Stage stage = (Stage) source.getScene().getWindow();
stage.close();
}
public Expense getNewExpense() {
return this.newExpense;
}
}
\ No newline at end of file
package no.ntnu.idatt1002.demo.controller;
import java.text.NumberFormat;
import java.time.LocalDate;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import no.ntnu.idatt1002.demo.data.Economics.Expense;
import no.ntnu.idatt1002.demo.data.Economics.Income;
import no.ntnu.idatt1002.demo.data.Economics.IncomeCategory;
public class AddIncomeController {
Income newIncome = null;
Income chosenIncome = null;
@FXML
private Button cancelBtn;
@FXML
private Button okBtn;
@FXML
private DatePicker datePicker;
@FXML
private TextField descriptionField;
@FXML
private TextField amountField;
@FXML
private ComboBox<IncomeCategory> categoryBox;
@FXML
private ComboBox<Boolean> recurringBox;
@FXML
public void initialize() {
ObservableList<IncomeCategory> incomeCategories = FXCollections.observableArrayList(
IncomeCategory.values());
categoryBox.setItems(incomeCategories);
categoryBox.setValue(IncomeCategory.GIFT);
ObservableList<Boolean> recurring = FXCollections.observableArrayList(true, false);
recurringBox.setItems(recurring);
recurringBox.setValue(false);
datePicker.setValue(LocalDate.now());
}
public IncomeCategory getCategory() {
return categoryBox.getValue();
}
public boolean isRecurring() {
return recurringBox.getValue();//.equals("Yes");
}
public void setIncome(Income income) { //TODO NEED CANCEL BUTTON TO REMOVE THE CHANGES IF CANCEL IS PRESSED
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());
chosenIncome.incomeCategoryObjectProperty().bindBidirectional(income.incomeCategoryObjectProperty());
chosenIncome.dateProperty().bindBidirectional(income.dateProperty());
descriptionField.textProperty().set(income.getDescription());
amountField.textProperty().setValue(String.valueOf(income.getAmount()));
recurringBox.setValue(income.isRecurring());
descriptionField.textProperty().set(income.getDescription());
amountField.textProperty().setValue(String.valueOf(income.getAmount()));
recurringBox.setValue(income.isRecurring());
datePicker.setValue(income.getDate());
categoryBox.setValue(income.getCategory());
}
@FXML
public void pressOkBtn(ActionEvent event) {
if (chosenIncome == null) {
LocalDate date = datePicker.getValue();
double amount = Double.parseDouble(amountField.getText());
String description = descriptionField.getText();
IncomeCategory category = getCategory();
boolean recurring = isRecurring();
newIncome = new Income(description, amount, recurring, category, date);
}
if (chosenIncome != null) {
chosenIncome.setDescription((descriptionField.getText()));
chosenIncome.setAmount(Double.parseDouble(amountField.getText()));
chosenIncome.setRecurring(recurringBox.getValue());
chosenIncome.setCategory(categoryBox.getValue());
chosenIncome.setDate(datePicker.getValue());
}
final Node source = (Node) event.getSource();
((Stage) source.getScene().getWindow()).close();
}
@FXML
public void pressCancelBtn(ActionEvent event) {
final Node source = (Node) event.getSource();
final Stage stage = (Stage) source.getScene().getWindow();
stage.close();
}
public Income getNewIncome() {
return this.newIncome;
}
}
\ No newline at end of file
package no.ntnu.idatt1002.demo.controller;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Modality;
import javafx.stage.Stage;
import no.ntnu.idatt1002.demo.data.Budget.BudgetItem;
import no.ntnu.idatt1002.demo.data.Budget.GeneralBudget;
import no.ntnu.idatt1002.demo.data.Economics.Expense;
import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class BudgetController {
private DialogMode dialogMode;
private GeneralBudget general = new GeneralBudget(31, 2000);
@FXML
private Button addBudget;
@FXML
private Button editBudget;
@FXML
private Button expenseBtn;
@FXML
private Button incomeBtn;
@FXML
private Button returnBtn;
@FXML
private Button nextBtn;
@FXML
private TableColumn<BudgetItem, Double> amountColumn;
@FXML
private TableView<BudgetItem> budgetTableView = new TableView<>();
@FXML
private TableColumn<BudgetItem, ExpenseCategory> categoryColumn;
@FXML
private TextArea daysVariable;
@FXML
private TableColumn<BudgetItem, String> descriptionColumn;
@FXML
private TextArea monthVariable;
@FXML
private TableColumn<?, ?> percentageColumn;
@FXML
private TextArea totalBudgetAmount;
@FXML
private ObservableList<BudgetItem> budgetList;
public void initialize() throws IOException {
budgetList = FXCollections.observableArrayList(general.getBudgetItems());
budgetTableView.setItems(budgetList);
categoryColumn.setCellValueFactory(new PropertyValueFactory<BudgetItem, ExpenseCategory>("budgetCategory"));
amountColumn.setCellValueFactory(new PropertyValueFactory<BudgetItem, Double>("budgetAmount"));
descriptionColumn.setCellValueFactory(new PropertyValueFactory<BudgetItem, String>("budgetDescription"));
}
@FXML
public void switchAddBudget(javafx.event.ActionEvent event) throws IOException {
BudgetItem item = null;
String dialogTitle = "";
FXMLLoader loader = new FXMLLoader(SceneController.class.getResource("/view/AddBudget.fxml"));
Dialog<BudgetItem> dialog = new Dialog<>();
dialog.initModality(Modality.APPLICATION_MODAL);
try{
dialog.getDialogPane().setContent(loader.load());
} catch(IOException e) {
e.printStackTrace();
}
AddBudgetController budgetController = loader.getController();
if(event.getSource().equals(addBudget)){
dialogMode = DialogMode.ADD;
dialogTitle = "New Budget";
}
else if (event.getSource().equals(editBudget) && budgetTableView.getSelectionModel().getSelectedItem() != null) {
dialogMode = DialogMode.EDIT;
dialogTitle = "Edit expense";
item = budgetTableView.getSelectionModel().getSelectedItem();
budgetController.setBudget(item);
} else {
return;
}
dialog.setTitle(dialogTitle);
dialog.showAndWait();
item = budgetController.getNewBudgetItem();
if(item != null && dialogMode == DialogMode.ADD){
try {
general.addToBudgetBudgetItem(item);
} catch(IllegalArgumentException e) {
showIllegalBudgetItemDialog();
}
}
refreshObservableList();
}
@FXML
public void closeButton(javafx.event.ActionEvent actionEvent) {
final Node source = (Node) actionEvent.getSource();
final Stage stage = (Stage) source.getScene().getWindow();
stage.close();
}
@FXML
public void deleteButton(ActionEvent event) {
BudgetItem item = budgetTableView.getSelectionModel().getSelectedItem();
if (item == null) {
return;
}
Optional<ButtonType> isConfirmed = showConfirmationDialog();
if (isConfirmed.isPresent() && isConfirmed.get() == ButtonType.OK) {
general.deleteItemFromBudget(item.getBudgetCategory());
refreshObservableList();
}
}
private Optional<ButtonType> showConfirmationDialog() {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Confirm Delete");
alert.setHeaderText("Delete Confirmation");
alert.setContentText("Are you sure you would like to delete the selected entry?");
return alert.showAndWait();
}
private Optional<ButtonType> showIllegalBudgetItemDialog() {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Budget amount exceeded");
alert.setHeaderText("Your budget exceeds the max limit");
alert.setContentText("The total budget sum must be below " + general.getMaxAmount());
return alert.showAndWait();
}
protected void refreshObservableList(){
budgetTableView.setItems(budgetList);
this.budgetList.setAll(general.getBudgetItems());
}
@FXML
public void switchScene(ActionEvent event) throws IOException {
//saveDataToFile("Income");
FXMLLoader loader = new FXMLLoader();
if (event.getSource() == expenseBtn) {
loader.setLocation(SceneController.class.getResource("/view/Expenses.fxml"));
} else if (event.getSource() == returnBtn) {
loader.setLocation(SceneController.class.getResource("/view/FirstMenu.fxml"));
} else if (event.getSource() == incomeBtn) {
loader.setLocation(SceneController.class.getResource("/view/Income.fxml"));
} else if (event.getSource() == nextBtn) {
loader.setLocation(SceneController.class.getResource("/view/MainMenu.fxml"));
}
Parent root = loader.load();
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
package no.ntnu.idatt1002.demo.controller;
import java.io.IOException;
import java.util.Optional;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Dialog;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Modality;
import javafx.stage.Stage;
import no.ntnu.idatt1002.demo.data.Economics.Expense;
import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory;
import no.ntnu.idatt1002.demo.data.Economics.ExpenseRegister;
import no.ntnu.idatt1002.demo.data.Economics.FileHandling;
import no.ntnu.idatt1002.demo.data.Economics.Income;
import no.ntnu.idatt1002.demo.data.Economics.IncomeRegister;
import no.ntnu.idatt1002.demo.data.Economics.Item;
import no.ntnu.idatt1002.demo.data.Economics.ItemRegister;
enum DialogMode {
ADD, EDIT, DELETE
}
public class ExpensesController {
/**
* The mode of the dialog. NEW if new contact, EDIT if edit existing contact.
*/
private DialogMode dialogMode;
@FXML
private Button addBtn;
@FXML
private Button editBtn;
@FXML
private Button deleteBtn;
@FXML
private ComboBox<String> show;
@FXML
private Button incomeBtn;
@FXML
private Button overviewBtn;
@FXML
private Button budgetBtn;
@FXML
private Button returnBtn;
@FXML
private TableColumn<Expense, Double> amountColumn;
@FXML
private TableColumn<Expense, ExpenseCategory> categoryColumn;
@FXML
private TableColumn<Expense, String> dateColumn;
@FXML
private TableColumn<Expense, String> descriptionColumn;
@FXML
private TableColumn<Expense, Boolean> recurringColumn;
@FXML
private TableView<Expense> expenseTableView;
@FXML
private TableView<Income> incomeTableView;
ExpenseRegister expenseRegister;
ObservableList<Expense> expenses;
ObservableList<String> filter;
@FXML
public void initialize()
throws IOException { //TODO SAME REGISTER FOR BOTH, BUT LOAD DIFFERENT DATA DEPENDING ON WHICH IT IS
dateColumn.setCellValueFactory(new PropertyValueFactory<Expense, String>("date"));
amountColumn.setCellValueFactory(new PropertyValueFactory<Expense, Double>("amount"));
categoryColumn.setCellValueFactory(
new PropertyValueFactory<Expense, ExpenseCategory>("category"));
descriptionColumn.setCellValueFactory(new PropertyValueFactory<Expense, String>("description"));
recurringColumn.setCellValueFactory(new PropertyValueFactory<Expense, Boolean>("recurring"));
filter = FXCollections.observableArrayList("All", "Food", "Clothes", "Books", "Other",
"Fixed expense");
expenseRegister = loadExpenseDataFromFile("Expense");
expenses = FXCollections.observableArrayList(expenseRegister.getItems());
expenseTableView.setItems(expenses);
show.setItems(filter);
show.setValue("All");
}
@FXML
protected void handleAddButton(ActionEvent event) {
handleEditButton(event);
}
@FXML
protected void handleEditButton(ActionEvent event) {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/view/AddExpense.fxml"));
Expense newExpense = null;
String dialogTitle = "";
// Load the FXML file for your dialog box
Dialog<Expense> dialog = new Dialog<>();
dialog.initModality(Modality.APPLICATION_MODAL);
try {
// Set the Dialog's content to the loaded FXML file
dialog.getDialogPane().setContent(loader.load());
} catch (IOException e) {
e.printStackTrace();
}
// Get the controller for the loaded FXML file
AddExpenseController dialogController = loader.getController();
if (event.getSource().equals(addBtn)) {
dialogMode = DialogMode.ADD;
dialogTitle = "Add expense";
} else if (event.getSource().equals(editBtn)
&& expenseTableView.getSelectionModel().getSelectedItem() != null) {
dialogMode = DialogMode.EDIT;
dialogTitle = "Edit expense";
newExpense = expenseTableView.getSelectionModel().getSelectedItem();
dialogController.setExpense(newExpense);
} else {
return;
}
dialog.setTitle(dialogTitle);
dialog.showAndWait();
// Show the Dialog and wait for the user to close it
//Get the newly created expense from the dialog pane
newExpense = dialogController.getNewExpense();
if (newExpense != null && dialogMode == DialogMode.ADD) {
expenseRegister.addItem(newExpense);
}
refreshObservableList();
}
//Only add the expense to the tableview, if the expense is not null
@FXML
public void handleDeleteBtn(ActionEvent event) {
Expense chosenExpense = expenseTableView.getSelectionModel().getSelectedItem();
if (chosenExpense == null) {
return;
}
Optional<ButtonType> isConfirmed = showConfirmationDialog();
if (isConfirmed.isPresent() && isConfirmed.get() == ButtonType.OK) {
expenseRegister.removeItem(chosenExpense);
refreshObservableList();
}
}
protected void refreshObservableList() {
this.expenses.setAll(expenseRegister.getItems());
}
private Optional<ButtonType> showConfirmationDialog() {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Confirm Delete");
alert.setHeaderText("Delete Confirmation");
alert.setContentText("Are you sure you would like to delete the selected entry?");
return alert.showAndWait();
}
public ExpenseRegister loadExpenseDataFromFile(String fileName) throws IOException {
//ItemRegister<T extends Item>
FileHandling fileHandling = new FileHandling();
if (fileHandling.isEmpty(fileName)) {
expenseRegister = new ExpenseRegister();
} else {
try {
expenseRegister = fileHandling.readExpenseRegisterFromFile(fileName);
} catch (IOException e) {
e.printStackTrace();
}
}
return expenseRegister;
}
public void saveDataToFile(String fileName) throws IOException {
FileHandling fileHandling = new FileHandling();
fileHandling.writeItemRegisterToFile(expenseRegister, fileName);
}
@FXML
public void switchScene(ActionEvent event) throws IOException {
saveDataToFile("Expense");
FXMLLoader loader = new FXMLLoader();
if (event.getSource() == incomeBtn) {
loader.setLocation(SceneController.class.getResource("/view/Income.fxml"));
} else if (event.getSource() == overviewBtn) {
loader.setLocation(SceneController.class.getResource("/view/Overview.fxml"));
} else if (event.getSource() == returnBtn) {
loader.setLocation(SceneController.class.getResource("/view/FirstMenu.fxml"));
} else if (event.getSource() == budgetBtn) {
loader.setLocation(SceneController.class.getResource("/view/BudgetNew.fxml"));
}
Parent root = loader.load();
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
package no.ntnu.idatt1002.demo.controller;
import java.io.IOException;
import java.util.Optional;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Dialog;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Modality;
import javafx.stage.Stage;
import no.ntnu.idatt1002.demo.data.Economics.Income;
import no.ntnu.idatt1002.demo.data.Economics.IncomeCategory;
import no.ntnu.idatt1002.demo.data.Economics.IncomeRegister;
import no.ntnu.idatt1002.demo.data.Economics.FileHandling;
import no.ntnu.idatt1002.demo.data.Economics.Income;
import no.ntnu.idatt1002.demo.data.Economics.IncomeRegister;
import no.ntnu.idatt1002.demo.data.Economics.Item;
import no.ntnu.idatt1002.demo.data.Economics.ItemRegister;
public class IncomeController {
/**
* The mode of the dialog. NEW if new contact, EDIT if edit existing contact.
*/
private DialogMode dialogMode;
@FXML
private Button addBtn;
@FXML
private Button editBtn;
@FXML
private Button deleteBtn;
@FXML
private ComboBox<String> show;
@FXML
private Button expenseBtn;
@FXML
private Button overviewBtn;
@FXML
private Button budgetBtn;
@FXML
private Button returnBtn;
@FXML
private TableColumn<Income, Double> amountColumn;
@FXML
private TableColumn<Income, IncomeCategory> categoryColumn;
@FXML
private TableColumn<Income, String> dateColumn;
@FXML
private TableColumn<Income, String> descriptionColumn;
@FXML
private TableColumn<Income, Boolean> recurringColumn;
@FXML
private TableView<Income> incomeTableView;
IncomeRegister incomeRegister;
ObservableList<Income> income;
ObservableList<String> filter;
@FXML
public void initialize()
throws IOException { //TODO SAME REGISTER FOR BOTH, BUT LOAD DIFFERENT DATA DEPENDING ON WHICH IT IS
dateColumn.setCellValueFactory(new PropertyValueFactory<Income, String>("date"));
amountColumn.setCellValueFactory(new PropertyValueFactory<Income, Double>("amount"));
categoryColumn.setCellValueFactory(
new PropertyValueFactory<Income, IncomeCategory>("category"));
descriptionColumn.setCellValueFactory(new PropertyValueFactory<Income, String>("description"));
recurringColumn.setCellValueFactory(new PropertyValueFactory<Income, Boolean>("recurring"));
filter = FXCollections.observableArrayList("All", "Gift", "Salary", "Student loan",
"Fixed income");
incomeRegister = loadIncomeDataFromFile("Income");
income = FXCollections.observableArrayList(incomeRegister.getItems());
incomeTableView.setItems(income);
show.setItems(filter);
show.setValue("All");
}
@FXML
protected void handleAddButton(ActionEvent event) {
handleEditButton(event);
}
@FXML
protected void handleEditButton(ActionEvent event) {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/view/AddIncome.fxml"));
Income newIncome = null;
String dialogTitle = "";
// Load the FXML file for your dialog box
Dialog<Income> dialog = new Dialog<>();
dialog.initModality(Modality.APPLICATION_MODAL);
try {
// Set the Dialog's content to the loaded FXML file
dialog.getDialogPane().setContent(loader.load());
} catch (IOException e) {
e.printStackTrace();
}
// Get the controller for the loaded FXML file
AddIncomeController dialogController = loader.getController();
if (event.getSource().equals(addBtn)) {
dialogMode = DialogMode.ADD;
dialogTitle = "Add income";
} else if (event.getSource().equals(editBtn)
&& incomeTableView.getSelectionModel().getSelectedItem() != null) {
dialogMode = DialogMode.EDIT;
dialogTitle = "Edit income";
newIncome = incomeTableView.getSelectionModel().getSelectedItem();
dialogController.setIncome(newIncome);
} else {
return;
}
dialog.setTitle(dialogTitle);
// Show the Dialog and wait for the user to close it
dialog.showAndWait();
//Get the newly created income from the dialog pane
newIncome = dialogController.getNewIncome();
if (newIncome != null && dialogMode == DialogMode.ADD) {
incomeRegister.addItem(newIncome);
}
refreshObservableList();
}
//Only add the income to the tableview, if the income is not null
@FXML
public void handleDeleteBtn(ActionEvent event) {
Income chosenIncome = incomeTableView.getSelectionModel().getSelectedItem();
if (chosenIncome == null) {
return;
}
Optional<ButtonType> isConfirmed = showConfirmationDialog();
if (isConfirmed.isPresent() && isConfirmed.get() == ButtonType.OK) {
incomeRegister.removeItem(chosenIncome);
refreshObservableList();
}
}
protected void refreshObservableList() {
this.income.setAll(incomeRegister.getItems());
}
private Optional<ButtonType> showConfirmationDialog() {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Confirm Delete");
alert.setHeaderText("Delete Confirmation");
alert.setContentText("Are you sure you would like to delete the selected entry?");
return alert.showAndWait();
}
public IncomeRegister loadIncomeDataFromFile(String fileName) throws IOException {
//ItemRegister<T extends Item>
FileHandling fileHandling = new FileHandling();
if (fileHandling.isEmpty(fileName)) {
incomeRegister = new IncomeRegister();
} else {
try {
incomeRegister = fileHandling.readIncomeRegisterFromFile(fileName);
} catch (IOException e) {
e.printStackTrace();
}
}
return incomeRegister;
}
public void saveDataToFile(String fileName) throws IOException {
FileHandling fileHandling = new FileHandling();
fileHandling.writeItemRegisterToFile(incomeRegister, fileName);
}
@FXML
public void switchScene(ActionEvent event) throws IOException {
saveDataToFile("Income");
FXMLLoader loader = new FXMLLoader();
if (event.getSource() == expenseBtn) {
loader.setLocation(SceneController.class.getResource("/view/Expenses.fxml"));
} else if (event.getSource() == overviewBtn) {
loader.setLocation(SceneController.class.getResource("/view/Overview.fxml"));
} else if (event.getSource() == returnBtn) {
loader.setLocation(SceneController.class.getResource("/view/FirstMenu.fxml"));
} else if (event.getSource() == budgetBtn) {
loader.setLocation(SceneController.class.getResource("/view/BudgetNew.fxml"));
}
Parent root = loader.load();
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
package no.ntnu.idatt1002.demo.controller;
import java.io.IOException;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import no.ntnu.idatt1002.demo.data.Economics.ExpenseRegister;
import no.ntnu.idatt1002.demo.data.Economics.IncomeRegister;
public class MainMenuController {
@FXML
private Button addExpenseBtn;
@FXML
private Button foodButton;
@FXML
private Button overviewBtn;
@FXML
private ProgressBar progressbar;
@FXML
private DatePicker date;
@FXML
private ImageView progressMarker;
@FXML
private Label today;
ExpenseRegister expenseRegister;
IncomeRegister incomeRegister;
@FXML
public void initialize() {
//expenseRegister = loadData();
//incomeRegister = loadData();
//progressbar.setProgress(expenseRegister.getTotalSum()/incomeRegister.getTotalSum());
progressMarker.setTranslateX(-275 + progressbar.getProgress());
today.setTranslateX(-275 + progressbar.getProgress());
}
@FXML
public void switchScene(ActionEvent event) throws IOException {
//saveDataToFile("Income");
FXMLLoader loader = new FXMLLoader();
if (event.getSource() == addExpenseBtn) {
loader.setLocation(SceneController.class.getResource("/view/Expenses.fxml"));
} else if (event.getSource() == overviewBtn) {
loader.setLocation(SceneController.class.getResource("/view/Budget.fxml"));
}
Parent root = loader.load();
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
package no.ntnu.idatt1002.demo.controller;
import java.io.IOException;
import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Modality;
import javafx.stage.Stage;
public class SceneController {
private Stage stage;
private Scene scene;
public void switchStartMenu(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/FirstMenu.fxml"));
Parent root = loader.load();
stage = (Stage)((Node)event.getSource()).getScene().getWindow();
scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public void switchNewBudget(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader(SceneController.class.getResource("/view/NewBudget.fxml"));
Parent root = loader.load();
stage = (Stage)((Node)event.getSource()).getScene().getWindow();
scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public void switchIncome(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader(SceneController.class.getResource("/view/Income.fxml"));
Parent root = loader.load();
stage = (Stage)((Node)event.getSource()).getScene().getWindow();
scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public void switchExpenses(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader(SceneController.class.getResource("/view/Expenses.fxml"));
Parent root = loader.load();
stage = (Stage)((Node)event.getSource()).getScene().getWindow();
scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public void switchOverview(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader(SceneController.class.getResource("/view/Overview.fxml"));
Parent root = loader.load();
stage = (Stage)((Node)event.getSource()).getScene().getWindow();
scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public void switchMainMenu(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader(SceneController.class.getResource("/view/MainMenu.fxml"));
Parent root = loader.load();
stage = (Stage)((Node)event.getSource()).getScene().getWindow();
scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public void addIncome(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader(SceneController.class.getResource("/view/addIncome.fxml"));
Scene newScene = new Scene(loader.load());
Stage newStage = new Stage();
newStage.setScene(newScene);
newStage.setResizable(false);
newStage.initModality(Modality.APPLICATION_MODAL);
newStage.show();
}
public void underProgress(ActionEvent event) throws IOException{
FXMLLoader loader = new FXMLLoader(SceneController.class.getResource("/view/underProgress.fxml"));
Scene newScene = new Scene(loader.load());
Stage newStage = new Stage();
newStage.setScene(newScene);
newStage.setResizable(false);
newStage.initModality(Modality.APPLICATION_MODAL);
newStage.show();
}
public void closeButton(ActionEvent actionEvent) {
final Node source = (Node) actionEvent.getSource();
final Stage stage = (Stage) source.getScene().getWindow();
stage.close();
}
}
package no.ntnu.idatt1002.demo.data.Budget;
import javafx.beans.property.*;
import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory;
import java.util.Objects;
/**
* This class represents a budgetItem
*
* @author Adele
*/
public class BudgetItem {
private DoubleProperty budgetAmount;
private ObjectProperty<ExpenseCategory> budgetCategory;
private StringProperty budgetDescription;
/**
* The constructor of a new Budgetitem.
*
* @param budgetAmount The amount of budget as a double
* @param description A description of the budget as a String
* @param category A category from ExpenseCategory
*
*/
public BudgetItem(double budgetAmount, String description, ExpenseCategory category){
this.budgetAmount = new SimpleDoubleProperty(budgetAmount);
this.budgetDescription = new SimpleStringProperty(description);
this.budgetCategory = new SimpleObjectProperty<ExpenseCategory>(category);
}
/**
* This method gets the BudgetAmount.
*
* @return the budgetAmount as a double
*
*/
public double getBudgetAmount() {
return budgetAmount.get();
}
public DoubleProperty getAmountProperty(){ return budgetAmount;}
public void setBudgetAmount(double amount){
this.budgetAmount.set(amount);
}
/**
* This method gets the category.
*
* @return the category as one of the categories in ExpenseCategory
*
*/
public ExpenseCategory getBudgetCategory() {
return budgetCategory.get();
}
public ObjectProperty<ExpenseCategory> getCategoryProperty(){ return budgetCategory; }
public void setBudgetCategory(ExpenseCategory category){
this.budgetCategory.set(category);
}
/**
* This method gets the description.
*
* @return the description as a String
*
*/
public String getBudgetDescription() {
return budgetDescription.get();
}
public StringProperty getDescriptionProperty(){ return budgetDescription; }
public void setBudgetDescription(String description){
this.budgetDescription.set(description);
}
@Override
public String toString() {
return "budgetAmount=" + getBudgetAmount() +
"\nbudgetCategory=" + getBudgetCategory() +
"\nbudgetDescription=" + getBudgetDescription();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof BudgetItem that)) return false;
return Objects.equals(budgetAmount.get(), that.budgetAmount.get()) && Objects.equals(budgetCategory.get(), that.budgetCategory.get()) && Objects.equals(budgetDescription.get(), that.budgetDescription.get());
}
@Override
public int hashCode() {
return Objects.hash(budgetAmount, budgetCategory, budgetDescription);
}
}
package no.ntnu.idatt1002.demo.data.Budget;
import no.ntnu.idatt1002.demo.data.Economics.*;
import java.io.*;
import java.time.LocalDate;
import java.util.ArrayList;
/**
* FileHandling is a class for writing and reading
* Budgets to and from a file.
*
* @author andreas
*/
public class FileHandlingBudget {
private static final String filePath = "src/main/resources/Budget/";
private static final String fileType = ".budget";
private static final String budgetPeriod = "budgetPeriod=";
private static final String maxAmount = "maxAmount=";
private static final String budgetAmount = "budgetAmount=";
private static final String budgetCategory = "budgetCategory=";
private static final String budgetDescription = "budgetDescription=";
/**
* Method for writing (adding) a budget to a file.
*
* @param generalBudget the budget 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 void writeGeneralBudgetToFile(String fileTitle, GeneralBudget generalBudget) throws IOException {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(filePath + fileTitle + fileType))) {
bw.write(generalBudget.toString());
} catch (IOException ex) {
throw new IOException("Error writing story to file: " + ex.getMessage());
}
}
/**
* Method for reading (getting) a Budget from a file.
*
* @param fileTitle the name of the file you want to read from.
* @return the GeneralBudget from the file.
* @throws IOException if an input or output exception occurred.
*/
public GeneralBudget readGeneralBudgetFromFile(String fileTitle) throws IOException {
GeneralBudget generalBudget = null;
int budgetPeriod = 0;
double maxAmount = 0;
ArrayList<BudgetItem> budgetItems = new ArrayList<>();
double budgetAmount = 0;
ExpenseCategory expenseCategory = null;
String budgetDescription = null;
try (BufferedReader br = new BufferedReader(new FileReader(filePath + fileTitle + fileType))) {
String line;
String nextLine = br.readLine();
while ((line = nextLine) != null) {
nextLine = br.readLine();
if(line.startsWith(FileHandlingBudget.budgetPeriod)) {
budgetPeriod = Integer.parseInt(line.replace(FileHandlingBudget.budgetPeriod, ""));
} else if (line.startsWith(FileHandlingBudget.maxAmount)) {
maxAmount = Double.parseDouble(line.replace(FileHandlingBudget.maxAmount,""));
} else if (line.startsWith(FileHandlingBudget.budgetAmount)) {
budgetAmount = Double.parseDouble(line.replace(FileHandlingBudget.budgetAmount,""));
} else if (line.startsWith(FileHandlingBudget.budgetCategory)) {
line = line.replace(FileHandlingBudget.budgetCategory, "");
expenseCategory = switch (line) {
case "FOOD" -> ExpenseCategory.FOOD;
case "CLOTHES" -> ExpenseCategory.CLOTHES;
case "BOOKS" -> ExpenseCategory.BOOKS;
default -> ExpenseCategory.OTHER;
};
} else if (line.startsWith(FileHandlingBudget.budgetDescription)) {
budgetDescription = line.replace(FileHandlingBudget.budgetDescription,"");
}
if ((line.isEmpty() || (nextLine == null)) && (expenseCategory!=null)) {
if(generalBudget == null){
generalBudget = new GeneralBudget(budgetPeriod,maxAmount);
generalBudget.addToBudget(budgetAmount,budgetDescription,expenseCategory);
} else{
generalBudget.addToBudget(budgetAmount,budgetDescription,expenseCategory);
}
}
}
}
return generalBudget;
}
}