Reference no: EM132355784
Question
Build a program to create two types of utility bills: water bill and electricity bill. Both types of bills have customer's name and address. They calculate charge differently.
(a) Design a Utility_bill class. This class has two protected instance variables: name and address. The __init__ method takes customer's name and address as two arguments and stores them in the instance variables. Add another protected instance variable total and initialized it to 0. Define two abstract methods calculate_charge and display_bill. These abstract methods have no real code. There is only one statement to raise a NotImplementedError exception
(b) Design a Water_bill class. This class is a derived class of the Utility_bill class. It has an additional protected instance variable to store number of gallons of water used. Define a calculate_charge method, which asks the user to enter number of gallons of water used and uses it to calculate total charge. Customers pay $0.005 per gallon for the first 6000 gallons, and $0.007 per gallon after the first 6000 gallons. Define a display_bill method to display customer's name, address, number of gallons of water used and total charge
(c) Build an Electricity_bill class. This class is a derived class of the Utility_bill class. It has an additional protected instance variable to store kilowatt hours used. Define a calculate_charge method, which asks the user to enter kilowatt hours used and uses it to calculate total charge. Customers pay $0.12 per kWh for the first 500 kWh, and $0.15 per kwh after the first 500 kWh. Define a display_bill method to display customer's name, address, number of kWh used and total charge
(d) In the main module, ask user to enter name and address. Ask the user to choose either water bill or electricity bill. Build an object and call its calculate_charge method to calculate total charge. Call the display_bill method to display the bill.
The following shows a sample test run. This user chooses water bill.
Enter name: John Doe
Enter address: 123 Happy Rd, Raleigh NC, 27603
Enter 1 for water bill, 2 for electricity bill: 1
How many gallons of water were used? 6002
Water Bill
Name: John Doe
Address: 123 Happy Rd, Raleigh NC, 27603
Gallons used: 6002.0
Please pay this amount: 30.014
The following shows another sample test run. This user chooses electricity bill.
Enter name: John Doe
Enter address: 123 Happy Rd, Raleigh NC, 27603
Enter 1 for water bill, 2 for electricity bill: 2
Enter kilowatt hours used: 502
Electricity Bill
Name: John Doe
Address: 123 Happy Rd, Raleigh NC, 27603
Kilowatt Hours used: 502.0
Please pay this amount: 60.3