Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

import java.util.Scanner; public class Race { public static void main(String[] Args) { // Read information from the user XXXXXXXXXXScanner scanIn = new Scanner(System.in);...

1 answer below »
import java.util.Scanner;
public class Race {
public static void main(String[] Args) {

Read information from the use
XXXXXXXXXXScanner scanIn = new Scanner(System.in);
XXXXXXXXXXSystem.out.print("\nHow long is the race > ");
XXXXXXXXXXdouble length = scanIn.nextDouble();
XXXXXXXXXXSystem.out.print("\nRace with Speedsters (yes/no) > ");
XXXXXXXXXXboolean speedster = (scanIn.next().toLowerCase()).equals("yes");
XXXXXXXXXXSystem.out.print("\nRace with Jalopies (yes/no) > ");
XXXXXXXXXXboolean jalopy = (scanIn.next().toLowerCase()).equals("yes");

Build an a
ay of racers
XXXXXXXXXXVehicle[] contestants = new Vehicle[8];
XXXXXXXXXXcontestants[0] = new RaceCar(110, "Corvette", 2);
XXXXXXXXXXcontestants[1] = new RaceCar(111, "Trans-Am", 1);
XXXXXXXXXXcontestants[2] = new RaceCar(109.99, "Cruiser");
XXXXXXXXXXcontestants[3] = new RaceCar(110.2, "BumbleBee", 3);

Only add jalopies if the user wants
/* UNCOMMENT ME FOR JALOPIES TO WORK
XXXXXXXXXXif (jalopy) {
XXXXXXXXXXcontestants[4] = new Jalopy(113.2, "Subaru", 3);
XXXXXXXXXXcontestants[7] = new Jalopy(113.3, "Toyota", 4);
}
*

Only add speedsters if the user wants
/* UNCOMMENT ME FOR SPEEDSTERS TO WORK
XXXXXXXXXXif (speedster) {
XXXXXXXXXXcontestants[5] = new Speedster(120.3, "Mach-5");
XXXXXXXXXXcontestants[6] = new Speedster(122.2, "Ford");
}
*
XXXXXXXXXXint carNum = 0;
XXXXXXXXXXint i = 0;
XXXXXXXXXXdouble min = contestants[0].timeToFinish(length);
XXXXXXXXXXdouble time = 0.0;
XXXXXXXXXXfor (Vehicle car : contestants) {
XXXXXXXXXXif (car != null) {
XXXXXXXXXXtime = car.timeToFinish(length);
XXXXXXXXXXSystem.out.print("" + contestants[i]);
XXXXXXXXXXSystem.out.printf(" finished in %3.2f Minutes\n\n", time);
XXXXXXXXXXif (time < min) {
XXXXXXXXXXmin = time;
XXXXXXXXXXcarNum = i;
}
}
XXXXXXXXXXi++;
}
XXXXXXXXXXSystem.out.print("The WINNER is ******\n" + contestants[carNum] +
" with a time of ");
XXXXXXXXXXSystem.out.printf("%3.2f minutes\n", min);
}
}

**
* Models a simple vehicle.
*
public abstract class Vehicle {
/** Speed of the vehicle *
private double speed;
/** Name of the vehicle *
private String name;
/**
*
Default
constructor.
* @param speed speed of the vehicle
* @param name name of the vehicle
*
public Vehicle(double speed, String name) {
XXXXXXXXXXthis.speed = speed;
XXXXXXXXXXthis.name = name;
}
/**
* In genreral the time it takes to finish a race is the length of the
* course divided by the car's speed. The speed of a car is found by
* taking the default speed and adding any speedboost and subtracting
* anything that slows the car down.
*
* @param length length of the track (not wo
ied about units)
* XXXXXXXXXXyou can assume miles.
*
public abstract double timeToFinish(double length);
/**
* Change the speed of the vehicle
* @param speed new speed for this vehicle
*
public void setSpeed(double speed) {
XXXXXXXXXXthis.speed = speed;
}
/**
* Change the name of the vehicle
* @param name new name for this vehicle
*
public void setName(String name) {
XXXXXXXXXXthis.name = name;
}
/**
* Find the name of this vehicle
* @return vehicle's name
*
public String getName() {
XXXXXXXXXXreturn name;
}
/**
* Find the max speed of this vehicle
* @return vehicle's speed
*
public double getSpeed() {
XXXXXXXXXXreturn speed;
}
public String toString() {
XXXXXXXXXXreturn name + " with a speed of " + speed;
}
}
Answered Same Day Oct 23, 2021

Solution

Arun Shankar answered on Oct 24 2021
152 Votes
Main.java
Main.java
class Main {
  public static void main(String[] args) {
    
    Race r = new Race(2.3, "tesla", 5, 4);
    System.out.println(r.timeToFinish(20));
  }
}
Race.java
Race.java
class Race extends Vehicle
{
  double slower;
  double boost;
  
 Constructor 
  Race(double _speed, String _name, double a, double b)
  {
    super(_speed, _name);
    slower = a;
    boost = b;
  }
  public double timeToFinish(double length)
  {
    double s = super.getSpeed() + boost - slower;
    return length / s;
  }
}
Vehicle.java
Vehicle.java
**
 * Models a simple vehicle.
 *
public abstract class Vehicle {
    /** Speed of the ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here