Kobby E.

asked • 05/23/21

COMPUTER SCIENCE

1. Write a class named Car that has the following data attributes:


a. __year_model (for the car’s year model) __make (for the make of the car) __speed (for the car’s current speed)

The Car class should have an __init__ method that accepts the car’s year model and make as arguments. These values should be assigned to the object’s __year_model and __make data attributes.

It should also assign 0 to the __speed data attribute.


The class should also have the following methods:


b. 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


2. Write a class named Pet, which should have the following data attributes:


a. __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 pet’s age)

The Pet class should have an __init__ method that creates these attributes. It should also have the following methods:


b. 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.


3. Write an Employee class that keeps data attributes for the following pieces of information:


a. Employee name


b. Employee number


Next, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information:


c. Shift number (an integer,such as1 for morning shift, 2 for evening shift)


d. Hourly payrate

Write the appropriate accessor and mutator methods for each class.


4. Design a recursive function that accepts an integer argument, n, and prints every second number from n down to a minimum of 0. Assume that n is always a positive integer.

1 Expert Answer

By:

Patrick B. answered • 05/23/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Kobby E.

Great work. Thanks ;)
Report

05/23/21

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.