Question & Answer: Write the code in PYTHON 3……

Write the code in PYTHON 3.

Write a program to count the number of vehicles and the amount of money collected at a tollbooth. The program should use a class named Register with instance variables for the number of vehicles processed and the total amount of money collected. One dollar should be collected for each car and two dollars for each truck. Provide a constructor and the following methods: setCount setTally getCount getTally ProccssCar ProcessTruck Be sure to define instance variables as needed by your “get”/”set” methods. sample Run: Enter type of vehicle (car/truck): car Number of vehicles: 1 Money Collected: $1.00 Do you want to enter more vehicles (Y/N)? Y Enter type of vehicle (car/truck): truck Number of vehicles: 2 Money Collected: $3.00 Do you want to enter more vehicles (Y/N)? N

Expert Answer

 

*Python 3 Code:

class Register:
    count = 0
    tally = 0.0

    #Increments the class variable count each time when this function is called
    def setCount(self):
        Register.count = Register.count + 1
    #Adding the amount sent to this function 1->car and 2->truck
    def setTally(self, amount):
        Register.tally = Register.tally + amount
    #Returning the no of vehicles
    def getCount(self):
        return Register.count
    #Returning the total amount collected
    def getTally(self):
        return Register.tally
    #Increment the vechicle count and increasing the tally by 1
    def ProcessCar(self):
        self.setCount()
        self.setTally(1)
    # Increment the vechicle count and increasing the tally by 2
    def ProcessTruck(self):
        self.setCount()
        self.setTally(2)

choice = 'Y'
while choice == 'Y':
    #Declaring an object of Register class
    register = Register()
    #Taking user input of whether car or truck
    vehicle = input("Enter type of vehicle (car/truck): ")
    if vehicle == "car":
        # If part is executed if car is chosen by the user
        register.ProcessCar()
        #Getting no of vehicles registered
        print("Number of vehicles: ", register.getCount())
        #Getting the amount collected
        print("Money Collected: $", register.getTally())
    else:
        #Else part is executed if truck is chosen by the user
        register.ProcessTruck()
        # Getting no of vehicles registered
        print("Number of vehicles: ", register.getCount())
        # Getting the amount collected
        print("Money Collected: $", register.getTally())
    #Asking the whether to continue or not
    choice = input("Do you want to enter more vehicles (Y/N)?")

**ScreenShot of sample output and input:

Still stressed from student homework?
Get quality assistance from academic writers!