Question: Assignment Description This assignment provides the opportunity to work with an array of objects and an object that contains another object. The array of objects

Assignment Description
This assignment provides the opportunity to work with an array of objects and an object that contains another object. The array of objects will hold race car objects and each race car object has an odometer object. The code will simulate a race in which each race car must race at least 500 miles. The race completes once all race cars have raced at least 500 miles.
In the code, perform four tasks:
Task 1: create the race car objects as described below and place them into an array.
Task 2: simulate a race until ALL the race cars reach at least 500 miles.
Task 3: display all race cars that have finished during each hour of the race.
Task 4: display the details for all races cars after the race is complete.
In this assignment, the completed program contains three classes:
Assignment11 contains main (test program that creates and works with the other 2 classes)
RaceCar represents one race car
Odometer represents the odometer in a race car
Details for both RaceCar and Odometer classes are provided in the Classes section below.
Specifications
Read these specifications to get an overview of assignment. When writing code, first create the classes.
1. Add this assignment to your project called CS1150
2. Create a Java class within that project called LastnameFirstNameAssignment11
3. Follow "CS1150 Programming Assignments Policy"
4. Write a test program (i.e. main) that:
Creates an array that stores 6 race cars.
Calls createRaceCars method to fill the array
i. This method creates the 6 race cars using the information in the following table and places the race cars into the array.
ii. Note: creation of the race cars is done manually in this method, so no user input is required to create the race cars. Hardcoding is allowed only in this method.
Race Car #
Driver
Average Race Speed
8
Shrek
85 mph
11
Fiona
115 mph
17
Donkey
70 mph
18
Dragon
100 mph
45
Pinocchio
80 mph
42
Farquaad
75 mph
Calls displayAllRaceCars method to display on the console the details for each race car.
i. Display the race car details before the race starts
ii. Race car #, driver, average speed, miles raced (zero at this point)
Call raceSimulation method to start the race!
i. See the Must Do and Tips section for information to help with this method.
Call displayAllRaceCars method to display on the console details for each car
i. Display the race car details at race completion.
ii. Display race car #, driver, average speed, and miles raced.
iii. The miles raced should have changed for each car.
Call writeCarDetailsToFile method to write the details for each race car to a file.
i. The code for this method is provided for you, see step #6 below.
5. The test program (i.e. main) must have these methods:
Place these methods after main inside the Assignment11 class
Note that static is needed on these methods since they are after main in the Assignment11 class
// Create the race cars for the race based on the assignment sheet table and
// fill the incoming array with the race cars
public static void createRaceCars(RaceCar[] raceCars)
// Display the details (drivers name and miles raced) for a single race car
public static void displayRaceCar(RaceCar raceCar)
// Display the details for each race car in the array
// Display race car #, driver name, average speed, and miles raced
public static void displayAllRaceCars(RaceCar[] raceCars)
// Simulate the race which continues until all car reach 500 miles
// See Must Do and Tips for details regarding this method
public static void raceSimulation(RaceCar[] raceCars)
// Determines if the race is finished.
// If the "finished" variable for all race cars is true, return true
// otherwise return false
public static boolean isRaceFinished(RaceCar[] raceCars)
// Print the details for each race car in the race cars array to a file
public static void writeRaceCarDetailsToFile(RaceCar[] raceCars) throws IOException
6. To start learning how to use files, do the following:
Include the writeRaceCarDetailsToFile method provided below in your code.
This method writes to a file the details for each race car at the end of the race simulation.
To write to a file:
i. Add the file processing pieces in steps a and b below to your code:
ii. Include the writeRaceCarDetailsToFile method provided in step c.
a) Include the import statements
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
b) Main needs to throw an IOException
public static void main(String[] args) throws IOException {
c) Copy the following code into your assignment. It will write the details for each race car in the array to a file named Assignment11.txt
public static void writeRaceCarDetailsToFile(RaceCar[] raceCars) throws IOException{
// Setup the file reference variable to refer to a text file.
// Assignment11.txt is the file that will be created on your hard drive.
File fil
Assignment Description This assignment provides

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Programming Questions!