Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON Write a program to create two types of utility bills: water bill and elec

ID: 3716697 • Letter: P

Question

PYTHON Write 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. Your project must follow these requirements.

(a) Create 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) Create 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) Create a 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. Create 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

Explanation / Answer

// Run following code in Python 3

class Utility_bill(object):

    def __init__(self, name, address):
        self._name = name
        self._address = address
        self._total = 0.0

    def calculate_charge(self):
        raise NotImplementedError("To be implemented")

    def display_bill(self):
        raise NotImplementedError("To be implemented")

class Water_bill(Utility_bill):

    def __init__(self, name, address, noofgallons):
        super().__init__(name, address)     
        self._noofgallons = noofgallons

    def calculate_charge(self):
        if self._noofgallons <= 6000:
            self._total = 0.005 * self._noofgallons
        else:
            self._total = 0.007 * self._noofgallons
  
    def display_bill(self):
        print("Water Bill")
        print("Name: ", self._name)
        print("Address: ", self._address)
        print("Gallons used: ", self._noofgallons)
        print("Please pay this amount: ", self._total)
      
class Electricity_bill(Utility_bill):
  
    def __init__(self, name, address, kilowatthours):
        super().__init__(name, address)     
        self._kilowatthours = kilowatthours

    def calculate_charge(self):
        if self._kilowatthours <= 500:
            self._total = 0.12 * self._kilowatthours
        else:
            self._total = 0.15 * self._kilowatthours
  
    def display_bill(self):
        print("Electricity Bill")
        print("Name: ", self._name)
        print("Address: ", self._address)
        print("Kilowatt Hours used: ", self._kilowatthours)
        print("Please pay this amount: ", self._total)

name = input("Enter name: ")
address = input("Enter address: ")
while True:
    n = int(input("Enter 1 for water bill, 2 for electricity bill: "))
    if n == 1:
        noofgallons = float(input("How many gallons of water were used? "))
        waterbill = Water_bill(name, address, noofgallons)
        waterbill.calculate_charge()
        waterbill.display_bill()
    elif n == 2:
        kilowatthours = float(input("Enter kilowatt hours used: "))
        electricitybill = Electricity_bill(name, address, kilowatthours)
        electricitybill.calculate_charge()
        electricitybill.display_bill()
    else:
        break

// Output


Enter name: John Doe                                                                                                          
Enter address: 123 Happy Rd, Raleig 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, Raleig NC, 27603                                                                                      
Gallons used: 6002.0                                                                                                         
Please pay this amount: 42.014                                                                                               
Enter 1 for water bill, 2 for electricity bill: 2
Enter kilowatt hours used: 502                                                                                                
Electricity Bill                                                                                                              
Name: John Doe                                                                                                               
Address: 123 Happy Rd, Raleig NC, 27603                                                                                      
Kilowatt Hours used: 502.0                                                                                                   
Please pay this amount: 75.3
Enter 1 for water bill, 2 for electricity bill: 3  

################ Please ask me if any queries. Thank you. #################