Question: I cant get my invoice method to work. As theres an error with my getters and I cant figure it out. Please help. Java programming.
I cant get my invoice method to work. As theres an error with my getters and I cant figure it out. Please help. Java programming. My classes are as follows:
public class Customer { private long accountNumber; private String customerName; private String street; private String city; private String state; private int zip;
public Customer(long accountNumber, String customerName, String street, String city, String state, int zip) { super(); this.accountNumber = accountNumber; this.customerName = customerName; this.street = street; this.city = city; this.state = state; this.zip = zip; } public long getAccountNumber() { return accountNumber; } public String getCustomerName() { return customerName; } public String getStreet() { return street; } public String getCity() { return city; } public String getState() { return state; } public int getZip() { return zip; } public void setCustomerName(String customerName) { this.customerName = customerName; } public void setStreet(String street) { this.street = street; } public void setCity(String city) { this.city = city; } public void setState(String state) { this.state = state; }
public void setZip(int zip) { this.zip = zip; } }
======================================================================
import java.time.LocalDate;
public class MeterReading { private LocalDate date; private double kilowattReading;
public MeterReading(LocalDate date, double killowattReading) { super(); this.date=date; this.kilowattReading=kilowattReading; }
public LocalDate getDate() { return date; }
public double getKilowattReading() { return kilowattReading; }
}
==========================================================================
import java.time.LocalDate;
public class Bill { Customer customer; private LocalDate billDate; private double kilowattCost; private double kilowattUsed; private double energyTax = 0.12; private double totalDue; private LocalDate dateDue; private double discountAmount; private LocalDate discountDate; private MeterReading startMeter; private MeterReading stopMeter; private double rate;
public Bill(LocalDate billDate, Customer customer, MeterReading startMeter, MeterReading stopMeter, double rate) { super(); this.billDate = billDate; this.customer = customer; this.startMeter = startMeter; this.stopMeter = stopMeter; this.rate = rate; }
public Customer getCustomer() { return customer; }
public LocalDate getBillDate() { return billDate; }
public double getKilowattCost() { return kilowattCost; }
public double getKilowattUsed() { return kilowattUsed; }
public double getEnergyTax() { return energyTax; }
public double getTotalDue() { return totalDue; }
public LocalDate getDateDue() { return dateDue; }
public double getDiscountAmount() { return discountAmount; }
public LocalDate getDiscountDate() { return discountDate; }
public MeterReading getStartMeter() { return startMeter; }
public MeterReading getStopMeter() { return stopMeter; }
public double getRate() { return rate; }
public void printInvoice() { System.out.println(" BILL"); System.out.println(); System.out.printf("REC Electric Co-Operative Date: %02d/%02d/%4d%n", billDate.getMonthValue(), billDate.getDayOfMonth(), billDate.getYear()); System.out.println(); System.out.printf("To: %s %s%n", customer.getCustomerName()); System.out.printf(" %s%n", customer.getStreet()); System.out.printf(" %s, %s, %5d%n", customer.getCity(), customer.getState(), customer.getZip()); System.out.println(); System.out.println("Meter Readings:"); System.out.println("Start Meter Reading:",getStartMeter() ); System.out.println("End Meter Reading:", getStopMeter() ); System.out.println(); System.out.println("Total KW used:", (getStopMeter() - getStartMeter()); System.out.println(); System.out.println("Cost of KW Used", getKilowattUsed(), * ,getRate() ); System.out.println("Energy Tax at", getEnergyTax() ); System.out.println(); System.out.println("Total Due" getTotalDue(), (getDateDue())); System.out.println("Discount Amount" getDiscountAmount(), (getDiscountDate()); } }




COSc 210-Object Oriented and GUI Programming Assignment 2 Due: Feburary 13th at 5:00 PM 30 points The objectives of this exercise are to: 1) Gain experience with using the Eclipse IDE 2) Gain an understanding of the basic definition and use of objects including the concepts; class, constructor, instance variables, reference variables, and get-er/set-er methods. 3) Gain skill in using expressions to compute values. 4) Gain skill in using printf to format a report. 5) Develop and test a simple Java program applying the concepts of objectives 2 3, and 4 AFTER YOU HAVE COMPLETED, put all of your files into a zip file named [your name)Assignment2.zip. Include all class and java files. Upload your zip file to Moodle Also print all source files and turn them in by the due date. cosc 210-COsc 21 0-Object Oriented and GUI Progrll Assignment 1 Problem Staten sed to produce monthly bills for Develop an application that an electric company may u its customers. A monthly bill for a customer is to be formatted as follows: its customer BILL Date: 02/12/2019 REC Electric Co-Operative To: John Jones Account: 389403020 99 Main street Bigtown, PA 15800 Meter Readings Start Meter Reading: 1231.2 KWH read on 01/10/2019 End Meter Reading: 1874.9 KWH read on 02/10/2019 Total KW Used: Cost of KW Used 643.7 x 0.132 per KWH 643.7 KWH Bill Computation: 84.97 $ 10.20 Energy Tax at 12 Total Due (date due 03/03/2019) Discount Amount (10% if paid by 02/22/2019) $ $ 95.17 86.67 For this application create three main classes for account (G.e., customer), meter reading. and bill. The account class should have six pieces of information (i.e. instance variables) including account number (as a long), customer name (as a String), customer address as four separate fields for street (as a String), city (as a String), state (as a String), and zip code (as an int. A meter reading represents a kilowatt reading on a given date. Thus, it should have two pieces in information consisting of date of reading (as a LocalDate), a the kilowatt reading (as a double). A Bill represents an amount that is due as a result a power consumption as calculated between one meter reading and its subsequent meter reading. A bill has 12 pieces of information including the account, a start meter readi and end meter reading, date of bill (as a LocalDate), total KW used (as a double), rat a double), cost of KW used (as a double), energy tax (as a double), total due (as a double), date due (as a LocalDate), discount amount (as a double) and discount date (as a LocalDate) For your account class, provide a constructor accepting values for all instance vari Provide getter and setter methods for all instance variables except account numbe has only a getter method. For your meter reading class provide a constructor accepting values for both ins variables. Provide only getter methods. For your bill class meter reading, stop variables with the values instance variables as follows: provide a constructor accepting only the date of bill, customer, start meter reading, and rate. In addition to setting the respective instance of the parameters, the constructor is to compute the rest of the Total KWu used-difference between the start and stop meter readings ost of KW used Energy tax Total due Date due total KW used times rate cost of KW used times 0.12 (for 1296) sum of cost of KW used and energy tax date 20 days following the date of the bill Discount amount-Total due less 10% of cost of Kw used Discount date due - date 10 days following the date of the bill For your bill class provide getter methods (no setters) for all instance variables and a print method to print the bill according to the format previously given. This class will have a main method. In the main method, create instances of your classes values to be used when instantiating your customer, meter reading, and bill classes. With In addition, develop another class to test your classes by printing three separate bills. in order to print the three separate bills. Thus, you will hard code inside the main the the exception of the fixed values given in the computations above (for example 0.12 for federal tax rate), do not hard code any other data within your customer, meter reading, and bill classes. For each bill instance, call the print method to print the bill. NOTE: You do not need, and therefore should not, code any routines to input the values from the user or from files. Your test class is sufficient to demonstrate that your customer, meter reading and bill classes are working correctly. BONUS 3 points: Handle the case where the meter rolls over. This can be detected if th ending meter reading is less than the start meter reading. Use the magnitude of the start meter reading to determine the roll over point (i.e., the maximum possible value upon which the meter will reset to zero). To represent a date/time use Java's LocalDate class (imported from java.time.LocallD For this class, however, do not use new to create instances. Instead use the static met of: LocalDate dateRead - LocalDate.of (2017, 1, 10); The above example creates a LocalDate for 1/10/2017. Methods getMonth0 getDayOfMonthO, and get Year0 can be used to get the month, day and, year from LocalDate object. Note that the method plusDays(n) can be used to create a nevw LocalDate so n days into the future. Date due - date 20 days following the dale U UI Discount amount-Total due less 10% of cost of KW used Discount date due - date 10 days following the date of the bill For your bill class provide getter methods (no setters) for all instance variables and a In addition, develop another class to test your classes by printing three separate bills. in order to print the three separate bills. Thus, you will hard code inside the main the the exception of the fixed values given in the computations above (for example 0.12 for reading, and bill classes. For each bill instance, call the print method to print the bill. print method to print the bill according to the format previously given. This class will have a main method. In the main method, create instances of your classes values to be used when instantiating your customer, meter reading, and bill classes. With federal tax rate), do not hard code any other data within your customer, meter NOTE: You do not need, and therefore should not, code any routines to input the values from the user or from files. Your test class is sufficient to demonstrate that your customer, meter reading and bill classes are working correctly BONUS 3 points: Handle the case where the meter rolls over. This can be detected if the ending meter reading is less than the start meter reading. Use the magnitude of the start meter reading to determine the roll over point (i.e., the maximum possible value upon which the meter will reset to zero). To represent a date/time use Java's LocalDate class (imported from java time.LocalDate) use Java's LocalDate class (imported from java.time.LocalDate) For this class, however, do not use new to create instances. Instead use the static method of: LocalDate dateRead - LocalDate.of(2017, 1, 10); The above example creates a LocalDate for 1/10/2017. Methods getMonthO. getDayOfMonthO, and getYear) can be used to get the month, day and, year from a LocalDate object. Note that the method plusDays(n) can be used to create a new LocalDate so n days into the future. Make sure the instance variables are private. Provide javadoc for each class and methods. Abide by good programming practices
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
