Answered step by step
Verified Expert Solution
Question
1 Approved Answer
5. Consider the following Ruby class: class MyCar def initialize(year, model, color) @year year @model-model @color- color @current-speed 0 end def brake (number) @current-speed-= number
5. Consider the following Ruby class: class MyCar def initialize(year, model, color) @year year @model-model @color- color @current-speed 0 end def brake (number) @current-speed-= number puts "You push the brake and decelerate #(number) mph." end def current_speed puts "You are now going #t@current-speedy mph..' end def shut dowrn @current-speed 0 puts "Let's park this bad boy!" end end List the instance variables belonging to the class MyCar. (2 points) Write a Ruby statement to create an instance of the class MyCar having the following initial values: year = 2017, model = Chevrolet Colorado, color = black (3 points) Write a Ruby statement to create a method called speed_up. The method should a) increase the speed of a car by the quantity of the given input parameter, and b) output a message indicating the updated speed of the car. (7 points)
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