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

This problem will create a monthly ledger for a user to keep track of monthly bi

ID: 3768009 • Letter: T

Question

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 : (blue indicates user entered information) 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

Explanation / Answer

The classes implemented has been mentioned.

Class Ourdate.java

import java.util.Scanner;

/*This class has been designed to get the date related information from the User.
The month date day are all provided as the imputs from the methods which has been used in this class.
*/

public class OurDate {
  
   private int month=0;
   private int year=0;
   private int day=0;
   Scanner scanner = new Scanner(System.in);
  
   //This is the Constructor that provides default value for the instance variables.
   public OurDate(){
   day = 0;
   month = 0;
   year = 1900;
   }
  
   //This method asks the user to set the date.
  
   public void setYearFromUser(){
   System.out.print("Enter the year : ");
   year = scanner.nextInt();
   }
  
   public int getYearFromUser(){
       return year;
   }
  
   //This method will convert thr data to string format
   public String toString(){
   return null;

   }
  
   //Set the current month form the user      
       public void setMonthFromUser(){
   System.out.print("Enter the month : ");
   month = scanner.nextInt();
   }
         
       public int getMonthFromUser() {
             
           return month;
       }
      
       //Set the day from the user for the billing date.
         
       public void setDayFromUser(){
   System.out.print("Enter the day : ");
   day = scanner.nextInt();
   }
      
       public int getDayFromUser(){
           return day;
       }

}

class Invoice.java

import java.util.Scanner;


public class Invoice {
  
   //Instance variables to get the Company Name, due date and the billable amount
  
   private String name=null;  
private OurDate date= new OurDate();
private double bilAmount=0;
  
Scanner scanner = new Scanner(System.in);
  
//This default constructor will set the bill amount to zero
  
int year =date.getYearFromUser();
int month= date.getMonthFromUser();
int day = date.getDayFromUser();

public Invoice(){
bilAmount = 0;
  

}
  
//This method sets the company name from the user
public void setCompanyNameFromUser(){
System.out.print("Enter the company name : ");
name = scanner.nextLine();
}
  
public String toString(){
// return name;
return (" Bill Summary :" +name +" " + bilAmount +" "+day +"/"+month+"/" +year);

}
  
public void printOp(){
   System.out.println(" Bill Summary :" +name +" " + bilAmount +" "+day +"/"+month+"/" +year);
  
}
  
   //This method set the date from the user.
   public void setDateFromUser(){
System.out.print("Enter invoice due date ");
//dueDat = scanner.nextInt();
}
  
   //Input the bill amount for that particular date.
   public void setBillAmountFromUser(){
System.out.print("Enter the bill amount : ");
bilAmount = scanner.nextDouble();
}

}

class Ledger.java

import java.util.Scanner;


public class Ledger {
  
   //private Invoice [] invoice;
private int numInvoices;
Scanner scanner = new Scanner(System.in);

//Default COnstructor
public Ledger(){

}
  
//Parametrised Constructor
public Ledger(int L){

}
  
public void getInvoiceInfo(){
System.out.println("Enter info for the invoice number 0 ");
}
public void printInvoiceInfo(){
  

}
public double calculateMonthBills(){
return numInvoices;

}   

}

class Assign4.java

import java.util.Scanner;

public class Assign4 {

private static int inv;

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
OurDate dat = new OurDate();
Invoice invoice = new Invoice();
Ledger ledger = new Ledger();
  
//Taking the number of the invoices as the input.

System.out.print("Enter the amount of monthly invoices: ");
inv = scanner.nextInt();

for(int i = 0; i < inv; i++) {

System.out.println(" Enter info for invoice number " + i);
invoice.setCompanyNameFromUser();
invoice.toString();
invoice.setBillAmountFromUser(); //Calling the respective menthods to get the data from the User.
invoice.setDateFromUser();
dat.setMonthFromUser();
dat.setYearFromUser();
dat.setDayFromUser();
// invoice.printOp();
  
invoice.scanner.nextLine(); // Need this line so new line is skipped
}
invoice.printOp();
}
}

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