Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA CODE PLEASE!!!!! You are going to create a simple car race program using th

ID: 3767612 • Letter: J

Question

JAVA CODE PLEASE!!!!!

You are going to create a simple car race program using the ideas of OOP to make several racing cars. These cars will “compete” to get to the end of the line first. The hard part will be creating and using the Car class/objects… but ultimately if you can make an array of integers and loop through that array increasing each integer … you can make this work too.

Specifications: Define a class called "Car" with the following properties:

Total Odometer Miles

Speed in miles per hour

Driver Name

Sponsor

Car Number

You should also include the following methods:

A method to make progress down the course

A method to convert your speed from MPH to MPS

A method to “pretty print” your car’s information including Number, Sponsor, Driver and Progress

A method to re-randomize speed

Include any useful methods in your class definition that you see fit

The total odometer miles should be initialized to zero, and speed initialized to a random value between 60 and 120.

Create a list of 20 vehicles with driver and sponsor names. You should not re-use a driver name or sponsor name (note – worry about this specification last, if you can make the race work w/o this, that’s better than getting hung up on this algorithm).

Your main program should simulate the progress of the vehicles in the race. You should accomplish this with a loop. Every 5 iterations of the loop (should be considered 1 minute of time), the vehicles pick a new random speed, and their odometer miles are updated every minute using this equation:

odometer_miles = odometer_miles + speed*time

Since speed is in miles per hour, time should be in hours as well (1 minute is 1/60th of an hour).

Remember for the sake of this assignment 1 minute = 5 loop iterations.

The first car to reach 100 miles should be declared the winner by printing the driver name and sponsor name.

Bonus +5: Create a 3rd Class with Static methods and properties to give drivers and sponsors. This will allow you to easily generate names for your Car class and encapsulate all the logic to make sure a driver or sponsor isn’t re-used.

Here are some String arrays that you can use to extract Driver and Sponsors:

String driverNameList = {"William Swopes", "Margurite Miland", "Alva Liska", "Bruna Breen", "Luciana Deshotel", "Jeannetta Nesbitt", "Donny Ledger", "Modesto Tennant", "Imelda Hassler", "Karma Agar", "Janis Wisneski", "Micha Dillow", "Mattie Boulden", "Ethelyn Boswell", "Erica Corvin", "Marion Holliday", "Laticia Repka", "Desirae Guarino", "Ines Wallach", "Deloris Kimbler", "Elliot Shatley", "Millicent Koller", "Bess Medellin", "Marcy Lydick", "Garnet Mccabe", "Donna Tannehill", "Dusti Devillier", "Leland Slemp", "Keiko Dolph", "Maybell Berggren", "Jeni Crew", "Christi Birdwell", "Una Sprague", "Sheba Mirza", "Alanna Wawrzyniak", "Francina Rippel", "Fermin Layne", "Taren Stetson", "Serina Reveles", "Maegan Arvizo", "Tajuana Behringer", "Tamara Havel", "Anya Gemmill", "Mel Bustle", "Tandy Nash", "Hue Stefan", "Reina Streett", "Glennie Kist", "Latricia Li", "Juliette Bureau"};

String listOfSponsors = {"Abercrombie & Fitch Co.", "ABM Industries Incorporated", "Ace Hardware Corporation", "ACT Manufacturing Inc.", "Acterna Corp.", "Adams Resources & Energy, Inc.", "ADC Telecommunications, Inc.", "Adelphia Communications Corporation", "Administaff, Inc.", "Adobe Systems Incorporated", "Adolph Coors Company", "Advance Auto Parts, Inc.", "Advanced Micro Devices, Inc.", "AdvancePCS, Inc.", "Advantica Restaurant Group, Inc.", "The AES Corporation", "Aetna Inc.", "Affiliated Computer Services, Inc.", "AFLAC Incorporated", "AGCO Corporation", "Agilent Technologies, Inc.", "Agway Inc.", "Apartment Investment and Management Company", "Air Products and Chemicals, Inc.", "Airborne, Inc.", "Airgas, Inc.", "AK Steel Holding Corporation", "Alaska Air Group, Inc.", "Alberto-Culver Company", "Albertson's, Inc.", "Alcoa Inc.", "Alleghany Corporation", "Allegheny Energy, Inc.", "Allegheny Technologies Incorporated", "Allergan, Inc.", "ALLETE, Inc.", "Alliant Energy Corporation", "Allied Waste Industries, Inc.", "Allmerica Financial Corporation", "The Allstate Corporation", "ALLTEL Corporation", "The Alpine Group, Inc.", "Amazon.com, Inc.", "AMC Entertainment Inc.", "American Power Conversion Corporation", "Amerada Hess Corporation", "AMERCO", "Ameren Corporation", "America West Holdings Corporation", "American Axle & Manufacturing Holdings, Inc.", "American Eagle Outfitters, Inc.", "American Electric Power Company, Inc."};

Breaking it down

Create the Car class and the _Race class (which includes your main) (ie: JustinSelgrad_Race.java)

Create an array of 20 Car objects each with a Driver and Sponsor, initialized as seen abve

o Create logic to prevent a duplicate name, but once again – don’t focus on this, get the race to work first Create a method to report the progress of the cars.

Create a loop to make the cars progress towards the goal!

Make sure you frequently report the progress of the cars.

Declare a winner by finding the first car to cross the finish line

! o You may consider writing a sort for your array to make this easier.

Explanation / Answer

//Program: CarRace.java (contains main.java)

package javaapplication87;

import java.util.ArrayList;

import java.util.List;

public class CarRace {

    public static void main(String[] args) {

        // TODO code application logic here

        //list of 20 vehicles

        int i,j;

        List <car> carList=new ArrayList <car>(20);

        String listOfSponsors[] = {"Abercrombie & Fitch Co.", "ABM Industries Incorporated",

       "Ace Hardware Corporation", "ACT Manufacturing Inc.", "Acterna Corp.", "Adams Resources "

       + "& Energy, Inc.", "ADC Telecommunications, Inc.", "Adelphia Communications Corporation",

       "Administaff, Inc.", "Adobe Systems Incorporated", "Adolph Coors Company", "Advance Auto Parts,"

       + " Inc.", "Advanced Micro Devices, Inc.", "AdvancePCS, Inc.", "Advantica Restaurant Group, Inc.",

       "The AES Corporation", "Aetna Inc.", "Affiliated Computer Services, Inc.", "AFLAC Incorporated",

       "AGCO Corporation", "Agilent Technologies, Inc.", "Agway Inc.", "Apartment Investment and Management"

     + " Company", "Air Products and Chemicals, Inc.", "Airborne, Inc.", "Airgas, Inc.", "AK Steel Holding"

      + " Corporation", "Alaska Air Group, Inc.", "Alberto-Culver Company", "Albertson's, Inc.", "Alcoa Inc.",

      "Alleghany Corporation", "Allegheny Energy, Inc.", "Allegheny Technologies Incorporated", "Allergan, Inc.",

      "ALLETE, Inc.", "Alliant Energy Corporation", "Allied Waste Industries, Inc.", "Allmerica Financial Corporation",

      "The Allstate Corporation", "ALLTEL Corporation", "The Alpine Group, Inc.", "Amazon.com, Inc.",

      "AMC Entertainment Inc.", "American Power Conversion Corporation", "Amerada Hess Corporation",

      "AMERCO", "Ameren Corporation", "America West Holdings Corporation", "American Axle & Manufacturing Holdings,"

      + " Inc.", "American Eagle Outfitters, Inc.", "American Electric Power Company, Inc."};

       

      String driverNameList[] = {"William Swopes", "Margurite Miland", "Alva Liska", "Bruna Breen", "Luciana Deshotel",

      "Jeannetta Nesbitt", "Donny Ledger", "Modesto Tennant", "Imelda Hassler", "Karma Agar", "Janis Wisneski",

      "Micha Dillow", "Mattie Boulden", "Ethelyn Boswell", "Erica Corvin", "Marion Holliday", "Laticia Repka",

      "Desirae Guarino", "Ines Wallach", "Deloris Kimbler", "Elliot Shatley", "Millicent Koller", "Bess Medellin",

      "Marcy Lydick", "Garnet Mccabe", "Donna Tannehill", "Dusti Devillier", "Leland Slemp", "Keiko Dolph",

      "Maybell Berggren", "Jeni Crew", "Christi Birdwell", "Una Sprague", "Sheba Mirza", "Alanna Wawrzyniak",

      "Francina Rippel", "Fermin Layne", "Taren Stetson", "Serina Reveles", "Maegan Arvizo", "Tajuana Behringer",

      "Tamara Havel", "Anya Gemmill", "Mel Bustle", "Tandy Nash", "Hue Stefan", "Reina Streett", "Glennie Kist",

      "Latricia Li", "Juliette Bureau"};

      for(i=0;i<20;i++)

      {

          car C=new car();

          C.CarNumber=i;

          C.DriverName=driverNameList[i];

          C.Sponsor=listOfSponsors[i];

        carList.add(C);

      }

      for(i=0;i<20;i++)

      {

          for(j=0;j<20;j++)

          {

          if((i+1)%5==0)

            {

                car C= carList.get(j);

                C.Speed=C.reRandomize();

                C.TotalOdometerMiles+= C.Speed*(1/60);

                carList.add(C);

                if(C.TotalOdometerMiles>=100)

                {

                    System.out.println();

                    break;

                }

            }

          }

      }

    }

   

}//========================================================

//Program: car.java

package javaapplication87;

public class car

{

public double TotalOdometerMiles;

public double Speed;

public String DriverName;

public String Sponsor;

public int CarNumber;

public car()

{

    TotalOdometerMiles=0;

    Speed=120 + (Math.random() * (60 - 120));

}

//method to make progress down the course

public void downTheCourse()

{

}

//A method to convert your speed from MPH to MPS

public void convertSpeed()

{

   

}

//A method to “pretty print” your car’s information including Number, Sponsor, Driver and Progress

public void printCar()

{

}

//A method to re-randomize speed

public void reRandomize()

{

}

    private double rand() {

        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

    }

}

package javaapplication87;

public class car

{

public double TotalOdometerMiles;

public double Speed;

public String DriverName;

public String Sponsor;

public int CarNumber;

public car()

{

    TotalOdometerMiles=0;

    Speed=120 + (Math.random() * (60 - 120));

}

//method to make progress down the course

public void downTheCourse()

{

}

//A method to convert your speed from MPH to MPS

public void convertSpeed()

{

   

}

//A method to “pretty print” your car’s information including Number, Sponsor, Driver and Progress

public void printCar()

{

   System.out.println("car Number"+this.CarNumber+" It's Driver: "+DriverName+" Sponsor: " +Sponsor +" Miles:"+this.TotalOdometerMiles);

}

//A method to re-randomize speed

public double reRandomize()

{

    return (120 + (Math.random() * (60 - 120)));

}

}