Question

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

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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\n");
//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\n");
}
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("\nEnter 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();
}
}

Add a comment
Know the answer?
Add Answer to:
This problem will create a monthly ledger for a user to keep track of monthly bills....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • College of Winston and Charlotte This program will calculate the amount for a semester bill at...

    College of Winston and Charlotte This program will calculate the amount for a semester bill at The College of Winston and Charlotte. Part 1: Create a class Course.java: The class has non-static instance variables: private String department private int courseNumber private int courseCredits private double courseCost The class must have a default constructor which will set values as follows: department = “unknown” courseNumber = 0 courseCost = 0 courseCredits = 0 The class must have a non-default constructor which will...

  • can you solve it in java please Create the following: 1. Class Invoice ( the node...

    can you solve it in java please Create the following: 1. Class Invoice ( the node ) that includes three instance variables:     int No; // the Invoice No             String CustName; // the Customer name             int Amount; // the Invoice Amount Invoice next; // points to the next Invoice Default and overloaded constructors 2. Class Shop that includes three instance variables: Invoice head; Invoice Tail; Your class should have the following: • A method that initializes the instance variables....

  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

  • PLEASE ANSWER IN C# 5. a. Create a Patient class for the Wrightstown Hospital Billing Department....

    PLEASE ANSWER IN C# 5. a. Create a Patient class for the Wrightstown Hospital Billing Department. Include auto-implemented prop- erties for a patient ID number, name, age, and amount due to the hospital, and include any other methods you need. Override the ToString method to return all the details for a patient. Write an application that prompts the user for data for five Patients. Sort them in patient ID number order and display them all, including a total amount owed....

  • a. Create a class named Lease with fields that hold an apartment tenant's name, apartment Number,...

    a. Create a class named Lease with fields that hold an apartment tenant's name, apartment Number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name. "XXX", the apartment number to O, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy...

  • You are to write a program (BookExceptionsDemo.java) that will create and, using user input, populate an...

    You are to write a program (BookExceptionsDemo.java) that will create and, using user input, populate an array of instances of the class Book. The class Book is loaded in our Canvas files: Book.java The user will enter a number n (n must be > 0, trap the user until they input a valid value for n), Your program will declare and create an array of size n of instances of the class Book. The user will be asked to enter...

  • Can you please help me with with problem. please follow all the specific insturctions, and try...

    Can you please help me with with problem. please follow all the specific insturctions, and try to make simple for a beginner in java. Write a class called Shape that contains instance data that represents the name and number of sides of the shape. Define a constructor to initialize these values. Include mutator(setter) methods – with the this reference – for the instance data, and a toString method that returns a the shape data. Create a static variable to keep...

  • Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEm...

    Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEmployee, HourlyEmployee which extend the Employee class and implements that abstract method. A Salary Employee has a salary, a Commision Employee has a commission rate and total sales, and Hourly Employee as an hourly rate and hours worked Software Architecture: The Employee class is the abstract super class and must be instantiated by one of...

  • Question 1 (Marks: 35) Create a class named Customer that will determine the monthly repayment amount...

    Question 1 (Marks: 35) Create a class named Customer that will determine the monthly repayment amount due by a customer for a product bought on credit. The class has five fields: customer name, contact number, product price, number of months and the monthly repayment amount. Write get and set methods for each field, except for the monthly repayment amount field. The set methods must prompt the user to enter the values for the following fields: customer name, contact number, product...

  • FOR JAVA: Summary: Create a program that stores info on textbooks. The solution should be named...

    FOR JAVA: Summary: Create a program that stores info on textbooks. The solution should be named TextBookSort.java. Include these steps: Create a class titled TextBook that contains fields for the author, title, page count, ISBN, and price. This TextBook class will also provide setter and getter methods for all fields. Save this class in a file titled TextBook.java. Create a class titled TextBookSort with an array that holds 5 instances of the TextBook class, filled without prompting the user for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT