Question: Your task is to take the race track program presented in class and add several parts to it. Add a new class called Motorcycle. It

Your task is to take the race track program presented in class and add several parts to it. Add a new class called Motorcycle. It should extend vehicle which will allow it to be a part of the array with other vehicles. Motorcycles have great speed (the speed you should set for your motorcycle instance should be 95) but are dangerous. Redefine ModifySpeed method so that the motorcycle will travel a random amount between 0 and their max speed. Additionally, since motorcycle extends vehicle you must redefine Go. Do so like Car, and Truck but add a conditional statement that checks for the motorcycles chance to crash which is 2% per loop. If the motorcycle crashes then it should not progress in the race any further (but it will restart in any future races).

Next we need to redefine the way passengers are kept track of in all vehicles. First passengers should be a private variable which can only be accessed by appropriate accessor and mutator methods. Finally we should add a new final variable for the max occupancy of the vehicle. The max occupancy should be checked in the mutator method for passengers. The max occupancy should be defined as:

o Car = 5

o Truck = 3

o Motorcycle = 1

If more passengers than are allowed attempt to pile into a vehicle the program should indicated this to the user and continue with the max passenger amount.

We want to change the race program from being 1 race to being a whole season. Do so by adding a looping structure to the main method. The season is defined as 25 races, and at the completion of all races the vehicle with the most wins should be printed (if 2 vehicles tie some tie-breaker should be conducted). For this section you may want to change when the vehicles get printed out so that they only print after races.

It is java programming.

source code is given below

package RaceTrackOriginal; //Remember that there are concepts here beyond what we have learned so far. This is given now to create a //tool to introduce those topics and get you to start asking the right questions. Start by getting it to run //and then play around with the code to try to understand what things do. Do try to remember some of the errors //that you get. Becoming familiar with them (and learning what makes them happen), will serve you well later //in the class. /** * This is the program driver (where the program starts) * It is in charge of creating the race and it's participants and telling them to "go" in the race. * @author vjl8401 */ public class RaceTrack { public final static int raceDuration = 1000; //store the length of the race (can be accessed anywhere in code) public static void main(String arg[]) { //Instantiating my object instances Vehicle c1 = new Car(1,2,85); //this one I'm storing as the base class (vehicle) Car c2 = new Car(2,3,100); //this one I store as the sub class (car). There are differences but they do not come into play here Truck t1 = new Truck(3,2,90,250); //This is an array Vehicle[] allVehicles = new Vehicle[3]; //placing the vehicles into an array allVehicles[0] = c1; allVehicles[1] = c2; //remember just because I store these as vehicles doesn't mean that the allVehicles[2] = t1; //methods for them has changed. Each still stores its own go method. //infinite loop (well without the base case it is) while (true) //this will run until a race participant crosses the finish line (passes raceDuration) { int max=0; //tell the cars to "go" one by one for (int i=0; i raceDuration) { break; } } System.out.println("We have a winner!!! *** Vehicle "+RaceTrack.GetFurthestVehicle(allVehicles)+" ***"); } //just a helper method to find out which vehicle won the race public static int GetFurthestVehicle(Vehicle[] allVehicles) { int max=0; int VIN=0; for (int i=0; i 

Your task is to take the race track program presented in class

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 Databases Questions!