Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can anybody help me with this ppleasee i m in hurry Write a class named Car that has the following data attributes: II year (for
can anybody help me with this ppleasee i m in hurry
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started