Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help Write a class named Car that has the following data attributes: II year (for the car's year} make model speed (for the car's

please help

image text in transcribed

image text in transcribed

Write a class named Car that has the following data attributes: II year (for the car's year} make model speed (for the car's current speed) The Car class should have an make data attributes. It should also assign 0 to the speed attribute. init_method that accepts the car's year, model, arn The class should also have the following methods: accelerate - The accelerate method should add 5 to the speed attribute each it is called. brake - The brake method should subtract 5 from the speed data attribute ea time it is called. get_speed - The get speed method should return the car's current speed. Next, design a program that creates a Car object and then calls the accelerate methc five times. After each call to the accelerate method, get the current speed of the car display it. Then call the brake method five times. After each call of the brake metho get the current speed of the car and display it. Sample Program Output: car is accelerating: Current speed: 5 Current speed: 10 Current speed: 15 Current speed: 20 Current speed: 25 car is braking: Current speed: 20 Current speed: 15 Current speed: 10 Current speed: 5 Current speed: 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions

Question

What is Working Capital ? Explain its types.

Answered: 1 week ago