car race codes..

Step 1 ?20 marks

Create the Car class. Each car has attributes for Odometer (int), Speed (int) and atPitstop (boolean). Have getters and setters for each.

Note on attributes:

The odometer is the total number of spaces the car has moved. For example, after 2 laps (when you create the CarDriver Main program), its odometer will be 80. Starting value is 0. Speed starts at 0.

atPitstop is a Boolean and starts at false. When the car lands in the atPitstop, this changes to true, and the car doesn抰 move on the next throw. After it has waited a turn, atPitstop changes to false and the car can continue.

Step 2 ?20 marks

The Aim here is to get one car to race around, without the special squares of atPitstop and speedBoost.

Create the Main program, called CarDriver. Here you will create an instance of the Car and the Die class. Have a variable called trackLength, just in case you would like to change it later. Use a while loop so the car races around for 10 laps.

Use a method to handle changes to the track position of the car. In this method you will get the old odometer reading, with getOdom(), add the die roll to it, and set the new odometer reading, with setOdom().

Use the following formula to give you the number of laps covered:

laps = carOne.getOdom() / trackLength;

This formula will tell you have many spaces you have covered in the current lap ( from (0,0):

inLap = carOne.getOdom()%( trackLength).

Each time the die is rolled, you should print out from the main values move number, die value, the lap number and the position in the lap.

Step 3 ?15 marks

Add the special squares atPitstop and speedBoost. Note that these squares should work the same even if the trackLength is changed.

Print out the speed. When you get a speed boost print out 揧ipee ?Extra Speed!!!!!!!!!!!!!!!!?br>

When you land in the atPitstop print out 揥HOA ?In the Pitstop?br>

Step 4 ?15 marks

Add a second car.

Print out something like ?Car One is winning by 34 spaces?after each move.

this is my assignment...

i just want few intro to this..

because im new to this..

i know how to start..

i seem to be stuck at middle part....

[2275 byte] By [icemansivaa] at [2007-10-2 0:55:50]
# 1

gee, i don't know. i've never done java homework before.

public class CarDriver{

public static void main(String[] args){

Car mycar = new Car();

Die mydie = new Die();

int trackLength = 80;

int laps = 0;

while(laps<10){

mycar.drive();

laps = mycar.getOdom() / trackLength;

}

}

}

walken16a at 2007-7-15 18:15:46 > top of Java-index,Java Essentials,New To Java...
# 2

Thank you, Mr/Ms Walken...

the only thing i dont know is and biggest problme now is that i dont know how to change the trackpositions...

it says it will be 40 in first place,

but is it in Car.java class or CarDriver.java class?...

the odometer should read like

odometer + die.getLastFace();

seriuosly i stuck at this..

whatever i do after this it wont work...

icemansivaa at 2007-7-15 18:15:46 > top of Java-index,Java Essentials,New To Java...