Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How do I achieve the final objective? With the truck class change the constructor so that an int for the horsepower is passed into the
How do I achieve the final objective? "With the truck class change the constructor so that an int for the horsepower is passed into the truck constructor instead of the entire engine this is the only data needed to create an engine use this to create the engine within the vehicle truck can pass the int up into vehicle if you add a constructor for this in vehicle Since truckVehicle creates its own engine within the object it is safer code than creating it in main or whoknowswhere."
I achieved the other objectives, but I have no idea how to start. This is the code:
import java.util.;
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 vjl
public class RaceTrackdriver
public final static int raceDuration ; store the length of the race can be accessed anywhere in code
public static void mainString arg
Instantiating my object instances
Engine engine new Engine;
Vehicle c new Carengine,; this one Im storing as the base class vehicle
Car c new Carnew Engine;
Truck t new Trucknew Engine;
Motorcycle m new Motorcycle new Enginef;
motorcycle won every single season. other vehicles have a chance
This is an array
Vehicle allVehicles new Vehicle;
placing the vehicles into an array
allVehicles c; polymorphism isa
allVehicles c; remember just because I store these as vehicles doesn't mean that the
allVehicles t; methods for them has changed. Each still stores its own go method.
allVehicles m;
int wins new int;store the number of wins
forint stage; stage;stage
boolean raceInProgresstrue;
System.out.printlnSTAGE stage;
while raceInProgress
int max;
tell the cars to go one by one
for int i; i raceDuration
System.out.printWinner of Stage stage:
Vehicle RaceTrackGetFurthestVehicleallVehicles
;
winsRaceTrackGetFurthestVehicleallVehicles;
System.out.println;
forint a;a allVehicles.length;a
allVehiclesareset;
raceInProgressfalse;
Systemout.println;
int pole wind;check to see who had the most wins
forint i;i;i
System.out.printlnVehicle allVehiclesiVIN : winsi wins";
ifwinsiwind
wind winsi;
polei;
System.out.printlnSEASON WINNER: VEHICLE pole;
just a helper method to find out which vehicle won the race
public static int GetFurthestVehicleVehicle allVehicles
int max;
int VIN;
for int i; i maxOccupancy
System.out.printlnOver capacity; only the maximum number of passengers will be allowed on
All others must leave the vehicle.";
this.passengersmaxOccupancy;
else
this.passengerspassengers;
public int getRaceProgress
return RaceProgress;
public void setRaceProgressint raceProgress
this.RaceProgress raceProgress;
Constructors used to create the objects:
Vehicleint vin, Engine horsePower, int maxPass
passengers ;
RaceProgress ;
VIN vin;
engine horsePower;
maxOccupancy maxPass;
This is the main function that progresses the vehicles through the race
this should be called each loop of the program this must be redefined in each
subclass of vehicle
abstract public void Go; this is correctly coded, the abstract method only has its header, and no body the body must be overwritten in subclasses
Part of object. This is invoked when an instance of this class is attempted to be used as a string like during System.out.println
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