Question: This program is in Java Define an abstract UtilityCustomer class that has one instance variable, an account number, and an abstract method, calculateBill, that returns

This program is in Java

Define an abstract UtilityCustomer class that has one instance variable, an account number, and an abstract method, calculateBill, that returns the bill amount as a double.

Also define the constructor, accessors, mutators, and a toString method that outputs the account number.

Define a GasCustomer class that inherits from the UtilityCustomer class, and adds an instance variable cubicMetersUsed and a constant for the price of gas per cubic meter.

Also define an ElectricCustomer class that also inherits from the UtilityCustomer class and adds a kWattHourUsed instance variable along with two constants for the price of electricity per kilowatt hour, plus a flat power delivery fee ($30) that is added to every bill.

For each subclass, define the constructor, accessor, and mutator for its instance variable, a toString method, which calls the toString method of the UtilityCustomer class, and an implementation for the calculateBill method.

Create a client that instantiates several GasCustomer and ElectricCustomer objects, adds them to an ArrayList of UtilityCustomer objects, and then using polymorphism, steps through the ArrayList, calling the calculateBill method and outputting the bill amount for each customer.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!