Question: Problem 1: Pet Class Write a class named Pet, which should have the following data attributes: __name (for the name of a pet) __animal_type (for
Problem 1: Pet Class
Write a class named Pet, which should have the following data attributes:
__name (for the name of a pet)
__animal_type (for the type of animal that a pet is. Example values are 'Dog', 'Cat', and 'Bird')
__age (for the pets age)
The Pet class should have an init method that creates these attributes. It should also have the following methods:
set_name: This method assigns a value to the __name field.
set_animal_type: This method assigns a value to the __animal_type field.
set_age: This method assigns a value to the __age field.
get_name: This method returns the value of the __name field.
get_animal_type: This method returns the value of the __animal_type field.
get_age: This method returns the value of the __age field.
Once you have written the class, write a program that creates an object of the class and prompts the user to enter the name, type, and age of his or her pet. This data should be stored as the objects attributes. Use the objects accessor methods to retrieve the pets name, type, and age and display this data on the screen.
Problem 2: Car Class
Write a class named Car that has the following data attributes:
__year_model (for the cars year model)
__make (for the make of the car)
__speed (for the cars current speed)
The Car class should have an init method that accepts the cars year model and make as arguments. These values should be assigned to the objects __year_model and __make data attributes. It should also assign 0 to the __speed data attribute.
The class should also have the following methods:
accelerate: The accelerate method should add 5 to the speed data attribute each time it is called.
brake: The brake method should subtract 5 from the speed data attribute each time it is called.
get_speed: The get_speed method should return the current speed.
Next, design a program that creates a Car object then calls the accelerate method five times. After each call to the accelerate method, get the current speed of the car and display it. Then call the brake method five times. After each call to the brake method, get the current speed of the car and display it.
Were supposed to do this in Visual Studio Code. Please include all of the code for this, thanks.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
