Menu

[Solved]Create Java Class Customerjava Represent Water Company Customer Contain Attributes Constru Q37250010

  1. Create a java class Customer.java that will represent a watercompany customer. It should contain the attributes, constructors,and methods listed below, and when finished should be able to allowthe included file TestWaterBills.java to work correctly.
  • Customer class
    • Attributes
      • firstName: String type, initial value null
      • lastName: String type, initial value null
      • streetAddress: String type, initial value null
      • city: String type, initial value null
      • state: String type, initial value null
      • zip: String type, initial value null
      • previousMeterReading: int type, initial value 0
      • currentMeterReading: int type, initial value 0
      • gallonsUsed: int type, initial value 0
      • currentCharges: double type, initial value 0.0
    • Constructors
      • Customer(): Default constructor
      • Customer(String first, String last, String street, String city,String state, String zip, int previousReading)
    • Methods
      • setCurrentMeterReading(int reading): void method
      • calculateGallonsUsed(): void method
      • calculateBill(): void method
      • toString(): String
      • getX/setX methods for all attributes listed above

More Info:

  1. When a customer is created some validation of information mustoccur:
    1. The state is a 2 character abbreviation, the value suppliedmust be exactly 2 characters in length
    2. The zip code must be 5 characters in length
    3. The value for previousMeterReading must be >= 0
    4. These rules must also be enforced in the “setters” provided forthese values as well as in the constructor.
    5. If a condition is invalidated throw an exception in theform

if (previousMeterReading < 0)

            thrownew RuntimeException(“The value for the previous meter reading is “+  “ invalid, it must be greater than or equal tozero”);

  1. method setCurrentMeterReading:  Thismethod sets the value for the data member“currentMeterReading”, if the value is<0  OR less than thepreviousMeterReadingfor the customer, an exceptionshould be thrown.  If a valid value is input, call theprivate method “calculateGallonsUsed” to set thegallonsUseddata member to the difference betweenthe previous meter reading the current meter reading.
  2. toString():  prints out all of thecustomer information ,  (all data members), along withthe amount of the current bill. Be sure to format the informationso that it is clear to read, and well organized.
  3. calculateBill:  This method computesa customer’s current bill based on the gallons used in the currentmonth and stores the result into the“currentCharges” data member.  Acustomers charges are calculated according to the followingrules:

Rate Schedule

gallons/month

rate

first 5,000

$10.90 per 1,000 gallons

next 5, 000

$10.55 per 1,000 gallons

next 10,000

$10.00 per 1, 000 gallons

next 10,000

$9.45 per 1,000 gallons

all Over 30,000

$8.60 per 1,000 gallons

The minimum customer bill is $31.54

Use String.format OR printf so that the bill isdisplayed correctly as dollars and cents with  2 decimalplaces.

What to turn in:

  • Customer.java

Expert Answer


Answer to Create a java class Customer.java that will represent a water company customer. It should contain the attributes, const… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *