Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hey there. I have a Java code for a small project which is called Money Manager. The main goal of it is to track your

Hey there. I have a Java code for a small project which is called Money Manager. The main goal of it is to track your income, expenses, etc. I have made the code already but I'm gonna need a few adjustments to the application with an explanation so I can learn (Please make sure to apply these and just read what I've written and edit accordingly. Thank you very much! Ok so here are the requirements so I can get a good mark for the code and these need to be fully met: 1. Design 3 to 4 classes - 3 marks 2. Private and public attributes - 0.5 marks 3. Set/get methods - 0.5 marks 4. Two or more constructors - 1 marks 5. Some functionality methods other than setter and getter - 1 marks 6. printDetails method (toString method) - 0.5 marks 7. At least 3 objects in the main method - 0.5 marks 8. Use an array (ArrayList preferable) - 1 marks 9. Write/read from/in file - 1 marks 10. Check input validation - 1 marks Must use aggregation and is logically applied. Here are the classes/codes: User class:

package moneymanager;

import java.util.ArrayList;

public class User { private String name; private ArrayList income; private ArrayList expenses;

public User(String name, ArrayList income, ArrayList expenses) { this.name = name; this.income = income; this.expenses = expenses; }

public String getName() { return name; }

public void setName(String name) { this.name = name; }

public ArrayList getIncome() { return income; }

public void setIncome(ArrayList income) { this.income = income; }

public ArrayList getExpenses() { return expenses; }

public void setExpenses(ArrayList expenses) { this.expenses = expenses; } }

-------------- Expense class:

package moneymanager;

public class Expense { private String category; private double amount;

public Expense(String category, double amount) { this.category = category; this.amount = amount; }

public String getCategory() { return category; }

public void setCategory(String category) { this.category = category; }

public double getAmount() { return amount; }

public void setAmount(double amount) { this.amount = amount; } }

------------------ Income class:

package moneymanager;

public class Income { private String source; private double amount;

public Income(String source, double amount) { this.source = source; this.amount = amount; }

public String getSource() { return source; }

public void setSource(String source) { this.source = source; }

public double getAmount() { return amount; }

public void setAmount(double amount) { this.amount = amount; } }

---------------- Test class:

package moneymanager;

import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Scanner;

public class Test { private ArrayList users;

public Test() { users = new ArrayList(); }

public void createUser() { Scanner input = new Scanner(System.in); System.out.print("Enter user name: "); String name = input.nextLine(); User user = new User(name, new ArrayList(), new ArrayList()); users.add(user); }

public void createIncome() { Scanner input = new Scanner(System.in); System.out.print("Enter user name: "); String name = input.nextLine(); User user = null; for (User u : users) { if (u.getName().equals(name)) { user = u; break; } } if (user == null) { System.out.println("User not found."); return; } System.out.print("Enter source of income: "); String source = input.nextLine(); System.out.print("Enter amount: "); double amount = input.nextDouble(); Income income = new Income(source, amount); user.getIncome().add(income); }

public void createExpense() { Scanner input = new Scanner(System.in); System.out.print("Enter user name: "); String name = input.nextLine(); User user = null; for (User u : users) { if (u.getName().equals(name)) { user = u; break; } } if (user == null) { System.out.println("User not found."); return; } System.out.print("Enter category of expense: "); String category = input.nextLine(); System.out.print("Enter amount: "); double amount = input.nextDouble(); Expense expense = new Expense(category, amount); user.getExpenses().add(expense); } public void addToFile() { try { try (FileOutputStream fos = new FileOutputStream("money-manager.txt"); ObjectOutputStream oos = new ObjectOutputStream(fos)) { oos.writeObject(users); } System.out.println("Data saved successfully to file"); } catch (IOException ioe) { } }

public void readFromFile() { try { try (FileInputStream fis = new FileInputStream("money-manager.txt"); ObjectInputStream ois = new ObjectInputStream(fis)) { users = (ArrayList) ois.readObject(); } System.out.println("Data loaded successfully from file"); } catch (IOException ioe) { System.out.println("Error reading from file"); } catch (ClassNotFoundException cnfe) { } }

public void displayDetails() { for (User user : users) { System.out.println("Name: " + user.getName()); System.out.println("Income:"); ArrayList userIncome = user.getIncome(); for (Income income : userIncome) { System.out.println("Source: " + income.getSource() + ", Amount: $" + income.getAmount()); } System.out.println("Expenses:"); ArrayList userExpenses = user.getExpenses(); for (Expense expense : userExpenses) { System.out.println("Category: " + expense.getCategory() + ", Amount: $" + expense.getAmount()); } System.out.println(" "); } } }

After editing what you need to edit in the codes to meet the requirements and explaining what you changed (so I could learn as well) please provide a UML like the following example: image text in transcribedI just need the sorting to be like this, doesn't have to be a drawing. Please feel free to edit the fields/attributes etc to fully meet the requirements. Also, make sure the addToFile works because I've tried loading from the file or adding to it. I just can't get it to work for some reason. When you finish coding please please please make sure you've met all the requirements and test the application for yourself if it fully works. Then send it. If it doesn't just take your time and edit. I know you can do this :) Thanks!

\begin{tabular}{l} Book \\ \hline -booksNames: \\ ArrayList \\ +price: double \\ +index :int \\ \hline + Book(:) \\ +Book(ArrayList b int i \\ double p): \\ +Book(int i): \\ +setBookNumber(ArrayList \\ b) :void \\ +getBookNumber(): \\ ArrayList \\ + bookList): void \\ + bookPrice(): void \\ +toString(): String \\ \end{tabular}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

why we face Listening Challenges?

Answered: 1 week ago

Question

what is Listening in Context?

Answered: 1 week ago