Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Expenses Tracker Juliana is a shopaholic! Juliana needs a software that helps he

ID: 3774664 • Letter: E

Question

Expenses Tracker Juliana is a shopaholic! Juliana needs a software that helps her keep track of her shopping expenses. Every time Juliana buys a new outfit, she would like to add it to a list of expenses and checks if she has exceeded her allowance of 700$ per month. She also likes to view all her expenses in a specific month. Each time Juliana buys a new outfit, she will need to keep track of the outfit type (i.e., shirt), the outfit price and the month (i.e., 1 for January) in which she bought the outfit. Your program should display the following menu for Juliana: *****Welcome to Shopaholic Software**** Menu 1- Enter a new Purchase.

2-Track Spending per Month

3-View purchases per Month 0-Exit

1

Please enter month of purchase

1

Please enter Type of outfit purchased Dress

Please enter Price of outfit purchased 300

Menu 1- Enter a new Purchase.

2-Track Spending per Month

3-View purchases per Month 0-Exit 2

Please enter month of purchase 1

The amount of money spent this month is 300$

Menu 1- Enter a new Purchase.

2-Track Spending per Month

3-View purchases per Month 0-Exit

3

Please enter month of purchase

1

You purchased on Month 1 the following:

Dress for 300$

Menu 1- Enter a new Purchase.

2-Track Spending per Month

3-View purchases per Month 0-Exit

0

Your program should allow Juliana to add as many purchases as she wants (hint: use Vectors to manage the purchases).

You will need to write two methods: 1) Write a method that returns the amount of money that Juliana spent for a specified month 2) Write a method that displays all the purchases of a specified month Your program needs to use the above methods to track the spending and to view the purchases per month.

Explanation / Answer

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Vector;

class Expenses{
   String outfitType;
   double price;
   public String getOutfitType() {
       return outfitType;
   }
   public void setOutfitType(String outfitType) {
       this.outfitType = outfitType;
   }
   public double getPrice() {
       return price;
   }
   public void setPrice(double price) {
       this.price = price;
   }
  
}
class ExpensesInMonth{
   int month;
   List<Expenses> expenseList;
   public int getMonth() {
       return month;
   }
   public void setMonth(int month) {
       this.month = month;
   }
   public List<Expenses> getExpenseList() {
       return expenseList;
   }
   public void setExpenseList(List<Expenses> expenseList) {
       this.expenseList = expenseList;
   }
     
}

public class ExpenseTracker {
   static Vector<ExpensesInMonth>expenseVector = new Vector<ExpensesInMonth>();
   static Scanner sc = new Scanner(System.in);
   public static void main(String[] args) {
      
       int month;
       int choice = 0;
       do{
       System.out.println("*****Welcome to Shopaholic Software****");
       System.out.println("Menu");
       System.out.println("1- Enter a new Purchase.");
       System.out.println("2-Track Spending per Month");
       System.out.println("3-View purchases per Month");
       System.out.println("0-Exit");
       choice = Integer.parseInt(sc.next());
       if(choice == 1){
           takeInput();
       }
       else if(choice == 2){
           do{
               System.out.println("Please enter month of purchase : ");
               month = Integer.parseInt(sc.next());
           }while(month > 12 && month < 1);
           double totalSpending = spendings(month);
           System.out.println("The amount of money spent this month is : "+totalSpending+"$");
       }
       else if(choice == 3){
           do{
               System.out.println("Please enter month of purchase : ");
               month = Integer.parseInt(sc.next());
           }while(month > 12 && month < 1);

           showSpendingByMonth(month);
       }
      
         
       }while(choice != 0);
   }
   private static void showSpendingByMonth(int month) {
      
      
       System.out.println("You purchased on Month "+month+" the following : ");
       if(expenseVector.size()>0){
           for(ExpensesInMonth ep :expenseVector){
               if(ep.getMonth() == month){
                   for(Expenses e : ep.getExpenseList()){
                       System.out.println(e.getOutfitType()+" for "+e.getPrice());
                  
                   }
               }
           }
       }
       else{
       System.out.println("list is empty");      
           }
      
      
   }
   private static double spendings(int month) {
      
      
       double totalSpend = 0.0;
       if(expenseVector.size()>0)
       for(ExpensesInMonth ep :expenseVector){
           if(ep.getMonth() == month){
               for(Expenses e : ep.getExpenseList()){
                   totalSpend += e.getPrice();
               }
           }
       }
      
       return totalSpend;
   }
   private static void takeInput() {
       int month;
       String type;
       double price;
       char choice;
       ExpensesInMonth expensesInMonth = null;
       List<Expenses> expenses = null;
       Expenses expense = new Expenses();
       System.out.println("Please enter month of purchase : ");
       month = Integer.parseInt(sc.next());
       double spending = spendings(month);
       if(spending > 700){
           System.out.println("You have exceeded allowance of 700$ per month");
           System.out.println("would you like to continue...(y)");
           choice = sc.next().charAt(0);
           if(choice != 'y'||choice != 'Y'){
               return;
           }
       }
       for(ExpensesInMonth ep :expenseVector){
           if(ep.getMonth() == month){
               expensesInMonth = ep;
              
           }
       }
      
      
       System.out.println("Please enter Type of outfit purchased : ");
       type = sc.next();
      
       System.out.println("Please enter Price of outfit purchased : ");
       price = Double.parseDouble(sc.next());
       if(price + spending >700){
           System.out.println("You have exceeded allowance of 700$ per month");
           System.out.println("would you like to continue...(y)");
           choice = sc.next().charAt(0);
           if(choice != 'y'||choice != 'Y'){
               return;
           }
       }
       if(expensesInMonth != null){
           expenseVector.remove(expensesInMonth);
           expenses = expensesInMonth.getExpenseList();
       }else{
           expensesInMonth = new ExpensesInMonth();
           expenses = new ArrayList<Expenses>();
       }
       expensesInMonth.setMonth(month);
       expense.setOutfitType(type);
       expense.setPrice(price);
       expenses.add(expense);
      
       expensesInMonth.setExpenseList(expenses);
       expenseVector.add( expensesInMonth);
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote