Question: Use the scaffold code provided for this task. Complete the following code requirements in the Ruby language for the file car.rb. Your final code must

Use the scaffold code provided for this task. Complete the following code requirements in the Ruby language for the file car.rb. Your final code must be structured and run.

Requirements:

1. You must create a record for a car. A car has the following attributes: an id (integer), a manufacturer (string), a model (string), and kilometres driven (integer). In your code create a Ruby class that can be used to create records for the car.

2. Write a function called read_car() that reads from the terminal values for each of the fields in an Car record and returns the completed record.

3. Write a procedure called display_car(car) that takes an car record and writes each of the fields to the terminal with a description for the field as well as the field value.

4. Write a function called read_cars() that calls your read_car() and returns an array of Cars.

5. Write a procedure called display_cars(cars); that calls your display_car(car) procedure for each car in the array.

6. Use the following code in your main() to test your program:


Code;

def read_cars()

end

def print_car(car)

end

def print_cars(cars)

end

def main()
cars = read_cars()
print_cars(carss)
end

main()

Step by Step Solution

3.50 Rating (157 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

car class has getters and initializer to input and retrieve cars class Car def initializeid manufacturer model kmsDriven id id manufacturer manufactur... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!