Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions