Question

*OBJECT ORIENTED PROGRAMMING* * JAVA PROGRAMMING* Create a program that simulates a race between several vehicles....

*OBJECT ORIENTED PROGRAMMING*

* JAVA PROGRAMMING*

Create a program that simulates a race between several vehicles.

Details don't matter must have the following:

  • Design and implement an inheritance hierarchy that includes Vehicle as an abstract superclass and several subclasses.
    • Include a document containing a UML diagram describing your inheritance hierarchy
  • Include at least one interface that contains at least one method that implementing classes must implement.
  • Include functionality to write the results of the race to a file; this will require Exception handling.
  • Utilize threads to ensure that all race vehicles are moving in turn.

Learning Outcomes

  • The student will be able to code a simple Object-oriented application that uses the primitive data types, arithmetic, selection, repetition, and relational operators along with creating and using arrays and ArrayLists.
  • The student will be able to describe and implement the concept of an interface and recognize when and why to use interfaces along with creating inheritance hierarchies.
  • The student will be able to throw and catch exceptions and create multi-threaded programs.

Homework Answers

Answer #1

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();
}
}
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT