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

Need Help Problem Description: This problem will create a monthly ledger for a u

ID: 3766973 • Letter: N

Question

Need Help

Problem Description: This problem will create a monthly ledger for a user to keep track of monthly bills.

The program will start by asking the user for an amount of monthly bills to pay.

Design of this solution will involve four classes, some may involve the use of previously written code:

Class Design:

OurDate class – update your previously written OurDate class to include a toString() method. Be certain that you still have methods that will setDayFromUser(), setMonthFromUser() and setYearFromUser(). As always, explicitly write a default constructor.

Invoice class – update your previously written Invoice class to include a name field (a String) and a toString() method. Be certain that you have methods that will setDateFromUser(),setNameFromUser(), and setAmountFromUser(), As always, explicitly write a default constructor.

Ledger class – fields will include an array of Invoice references, and also an integer that will represent the number of invoices in the array. Two constructors are required, a default constructor (no input parameters) and also an overloaded constructor that receives an integer as an input parameter, and ultimately will be used in order to instantiate the Invoice array. Include methods getInvoiceInfo() (invokes the setDateFromUser(),setNameFromUser(), and setAmountFromUser() methods from the Invoice class), printInvoiceInfo() (invokes the toString() method from the Invoice class, and a calculateMonthBills() (invokes a getAmount() method from the Invoice class that returns a double).

Assign4 class – this class will be the main() "driver" class. Create an object of Ledger class. Prompt the user for a number of invoices, and pass this integer as a formal parameter when instantiating the Ledger reference variable. Invoke the methods getInvoiceInfo(),calculateMonthBills(), and printInvoiceInfo().

Sample Output :

Enter the amount of monthly invoices: 3

Enter info for invoice number 0 :

Enter Company Name: Bell Canada

Enter bill amount: 47.10

Enter invoice due date:

Enter day: 1

Enter month: 12

Enter year: 2015

Enter info for invoice number 1 :

Enter Company Name: Enbridge

Enter bill amount: 55.38

Enter invoice due date:

Enter day: 5

Enter month: 12

Enter year: 2015

Enter info for invoice number 2 :

Enter Company Name: Hydro Enter bill amount: 33.11

Enter invoice due date:

Enter day: 15

Enter month: 12

Enter year: 2015

Total monthly bills: 135.59

Bill Summary : Bell Canada

47.10

1/12/2015

Enbridge

55.38

5/12/2015

Hydro

33.11

15/12/2015

OurDate

import java.util.Scanner;

public class OurDate {


   private int month ;
   private int day ;
   private int year ;

   public OurDate () {

       month = 1;
       day = 1;
       year = 1900;
       }
  
  
  
   public void setYear(){

       Scanner keyborad = new Scanner(System.in);

       System.out.print("Enter a valid year:");

       year=keyborad.nextInt();

       }
  
   public void setMonth(){

       Scanner keyborad2 =new Scanner(System.in);

       System.out.print("Enter the month: ");

       month=keyborad2.nextInt();

       }
  
   public void setDay(){

       Scanner keyborad3 = new Scanner(System.in);

       System.out.print("Enter the day:");

       day=keyborad3.nextInt();

       }

Invoice

import java.util.Scanner;

public class Invoice {


  
   private double invoiceAmount;
   private double interest;
   private double tax;
   private double totalAmount;
  
private OurDate dueDate;


   public Invoice(){
  
       invoiceAmount=0;
       interest=0;
       tax=0;
       totalAmount=0;
       dueDate= new OurDate();
      
   }


   public void setName(){
      
      
   }


   public void setDates(){
       System.out.println("Enter today's date:");
       dueDate.setYear();
       dueDate.setMonth();
       dueDate.setDay();

   }

Explanation / Answer

Program:

Code to be copied by the user:

OurDate.java:

import java.util.*;

public class OurDate {

     private int month;

     private int day;

     private int year;

    

     public OurDate() {

          month = 1;

          day = 1;

          year = 1900;

     }

     public OurDate(int d, int m, int y)

     {

          day = d;

          month = m;

          year = y;

     }

    

     public void setDayFromUser() {

          Scanner keyborad3 = new Scanner(System.in);

          System.out.print("Enter the day: ");

          day = keyborad3.nextInt();

          while(day>31 || day<=0)

          {

              System.out.println("Invalid day. Enter valid day: ");

              day=keyborad3.nextInt();

          }

     }

    

     public void setMonthFromUser() {

          Scanner keyborad2 = new Scanner(System.in);

          System.out.print("Enter the month: ");

          month = keyborad2.nextInt();

          while(month>12 || month<=0)

          {

             System.out.println("Invalid Entry Enter Again");

             month = keyborad2.nextInt();

          }

     }

         

     public void setYearFromUser() {

          Scanner keyborad = new Scanner(System.in);

          System.out.print("Enter a valid year: ");

          year = keyborad.nextInt();  

     }

     public String toString()

     {

          return (day+" / "+month+" / "+year);

     }

}

Invoice.java:

import java.util.*;

public class Invoice

{

     private double invoiceAmount;

     private double interest;

     private double tax;

     private double totalAmount;

     private OurDate dueDate;

     private String name;

     public Invoice()

     {

          invoiceAmount=0;

          interest=0;

          tax=0;

          totalAmount=0;

          dueDate= new OurDate();

          name="";

     }

    

     public void setAmountFromUser()

     {

          Scanner sc = new Scanner(System.in);

          System.out.println("Enter bill amount: ");

          invoiceAmount = sc.nextDouble();

     }

    

     public void setNameFromUser()

     {

          Scanner sc = new Scanner(System.in);

          System.out.println("Enter Company name: ");

          name = sc.nextLine();  

     }

     public void setDateFromUser()

     {

          System.out.println("Enter invoice due date:");

          dueDate.setDayFromUser();

          dueDate.setMonthFromUser();

          dueDate.setYearFromUser();

     }

    

     public double getTotalAmount()

     {

          return totalAmount;

     }

    

     public double getAmount()

     {

          return invoiceAmount;

     }

    

     public String toString()

     {

          return (invoiceAmount + " " + name + " " + dueDate.toString());

     }

}

Ledger.java:

import java.util.*;

public class Ledger

{

     ArrayList<Invoice> invoices;

     public int numberOfInvoices;

     public Ledger() {

          this.numberOfInvoices = 0;

          this.invoices = new ArrayList<Invoice>();

     }

     public Ledger(ArrayList<Invoice> invoices, int numberOfInvoices) {

          this.invoices = invoices;

          this.numberOfInvoices = numberOfInvoices;

     }

     public void setInvoices(ArrayList<Invoice> invoices) {

          this.invoices = invoices;

     }

     public void setNumberOfInvoices(int numberOfInvoices) {

          this.numberOfInvoices = numberOfInvoices;

     }

     public void getInvoiceInfo()

     {

          for(int i=0;i<numberOfInvoices;i++)

          {

              System.out.println("Enter info for invoice number "+ i + ":");

              invoices.add(new Invoice());

              invoices.get(i).setNameFromUser();

              invoices.get(i).setAmountFromUser();

              invoices.get(i).setDateFromUser();

              System.out.println();

          }

     }

    

     public void calculateMonthBills()

     {

          double total=0;

          for(int i=0;i<invoices.size();i++)

          {

              total+=invoices.get(i).getAmount();            

          }

          System.out.println("Total monthly bills: " +total);

     }

         

     public void printInvoiceInfo()

     {

          for(int i=0;i<invoices.size();i++)

          {

              System.out.println(invoices.get(i).toString());

              System.out.println();

          }

     }

}

Assign4.java:

import java.util.*;

public class Assign4

{

     public static void main(String args[])

     {

          Ledger ledger = new Ledger();

          Scanner sc = new Scanner(System.in);

          System.out.println("Enter the amount of monthly invoices: ");

          int invoices = sc.nextInt();

          ledger.setNumberOfInvoices(invoices);

          ledger.getInvoiceInfo();

          ledger.calculateMonthBills();

          ledger.printInvoiceInfo();

     }

}

Sample Output:

Enter the amount of monthly invoices:

3

Enter info for invoice number 0:

Enter Company name:

Bell Canada

Enter bill amount:

47.10

Enter invoice due date:

Enter the day: 1

Enter the month: 12

Enter a valid year: 2015

Enter info for invoice number 1:

Enter Company name:

Enbridge

Enter bill amount:

55.38

Enter invoice due date:

Enter the day: 5

Enter the month: 12

Enter a valid year: 2015

Enter info for invoice number 2:

Enter Company name:

Hydro

Enter bill amount:

33.11

Enter invoice due date:

Enter the day: 15

Enter the month: 12

Enter a valid year: 2015

Total monthly bills: 135.59

47.1

Bell Canada

1 / 12 / 2015

55.38

Enbridge

5 / 12 / 2015

33.11

Hydro

15 / 12 / 2015

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