*OBJECT ORIENTED PROGRAMMING*
* JAVA PROGRAMMING*
Create a program that simulates a race between several vehicles.
Details don't matter must have the following:
Learning Outcomes
This will be the program for the following:
public class RaceCar extends Thread
{
private int finish;
private String name;
public RaceCar(int finish, String name)
{
this.finish = finish;
this.name = name;
}
public void run()
{
for(int i = 1; i <= finish; i++)
{
int time = (int) (Math.random() * 6000);
try
{
Thread.sleep(time);
}catch(InterruptedException m)
{}
System.out.println(name + " " + i);
}
System.out.println(name + " finished!");
}
}
for the main program
public class Race
{
public static void main(String [] args)
{
Thread [] cars = new Thread[5];
int laps = Integer.parseInt(args[5]);
for(int i = 0; i < cars.length; i++)
{
cars[i] = new RaceCar(laps, args[i]);
}
for(int i = 0; i < cars.length; i++)
{
cars[i].start();
}
}
}
Get Answers For Free
Most questions answered within 1 hours.