Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

JAVA Implement a RaceTrack class has an array of Cars. Specifically, it has the following private attributes: name (String) //this holds track name single word

JAVA

Implement a RaceTrack class has an array of Cars. Specifically, it has the following private attributes:

  • name (String) //this holds track name single word
  • Car [] cars //an array of Cars
  • maxNum (int) //this is the maximum number of cars a race track can have
  • currNum (int) //this is the current number of cars on the race track

and the following methods:

  • Constructor (sets the name and maximum number of cars from defined values) AND initializes the car array to the max number of cars AND sets the currNum to 0
  • Get and set methods.
  • toString method returns the name of the race track and number of cars on the race track
  • addCar (Car) method adds the passed in car to the array if there is room (if there is no room, then it is not added. Dont forget to update the current number of cars if you successfully add a car. It returns true or false based on whether a car was added or not.
  • printAllCars which prints the name of the race track, followed by each car on the race track on a new line (you can use the cars own toString method to print the information)

Then create a RaceTrackDemo class to create and use Car objects. The demo class contains the main method. Use a Scanner object to create:

  • one RaceTrack object by reading in the name of the race track and maximum number of cars
  • Then create three Car objects by reading in the make and topSpeed of the three cars
  • Add the three cars to the race track
  • Print the race track (use the toString method)
  • Print all the cars on the race track (call the printAllCars method).

Details

Input

The name of the racetrack and its max number of cars. Then the make, model and top speed for 3 different cars: {name of racetrack} {max number of cars} {make of car1} {top speed of car1} {make of car2} {top speed of car2} {make of car3}

Example Input: KawarthaRaceTrack 8 BMW 200 Audi 240 Porsche 250

Output

Example Output: KawarthaRaceTrack has 3 cars BMW Top Speed: 200 Audi Top Speed: 240 Porsche Top Speed: 250

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions