PLEASE HELP ME.....

This the the the Lane Class:

import java.util.*;

import java.io.*;

import java.*;

public class Lane

{

public String[][] lane = new String[10][3];

int car1 = 0;

int car2 = 0;

int car3 = 0;

int car4 = 0;

public int bool = 1;

Random random = new Random();

public String[][] addCar()

{

while(bool == 1)

{

Random random = new Random();

int randomInt = random.nextInt(4);

if(randomInt == 0)

{

car1++;

lane[0][0] = "<=>";

moveL1();

}

if(randomInt == 1)

{

car2++;

lane[0][1] = "<=>";

moveL2();

}

if(randomInt == 2)

{

car3++;

lane[10][2] = "<=>";

moveR1();

}

if(randomInt == 3)

{

car4++;

lane[10][3] = "<=>";

moveR2();

}

return lane;

}

return lane;

}

public String[][] moveL1()

{

int i=0;

int j=1;

while(bool==1)

{

for(int a=0; a<=10; i++)

{

String temp=lane[0];

lane[0]=lane[j][0];

lane[j][0]=temp;

return lane;

}

lane[10][0] = "";

break;

}

return lane;

}

public String[][] moveL2()

{

int i=0;

int j=1;

while(bool==1)

{

for(int a=0; a<=10; i++)

{

String temp=lane[1];

lane[1]=lane[j][1];

lane[j][1]=temp;

return lane;

}

lane[10][1] = "";

break;

}

return lane;

}

public String[][] moveR1()

{

int i=10;

int j=9;

while(bool==1)

{

for(int a=0; a<=10; i++)

{

String temp=lane[2];

lane[2]=lane[j][2];

lane[j][2]=temp;

return lane;

}

lane[0][2] = "";

break;

}

return lane;

}

public String[][] moveR2()

{

int i=10;

int j=9;

while(bool==1)

{

for(int a=0; a<=10; i++)

{

String temp=lane[3];

lane[3]=lane[j][3];

lane[j][3]=temp;

return lane;

}

lane[0][3] = "";

break;

}

return lane;

}

}

And this is the Tester class:

/**

* @(#)LaneTest.java

*

*

* @Jeff Cho

* @SID 307144283

* @created 2007/4/30

*/

public class LaneTest

{

addCar car = new addCar();

}

This program is suppose to simulate how a car move on a lane (in terms of array).

The Lane Class compiled perfectly.

But the LaneTest, have 1 error:

Invalid method declaration; return type need

I dont understand why, Please help me....

[2800 byte] By [Jeffski_kuna] at [2007-11-27 3:51:43]
# 1

Please use the code tags.

addCar is not a class to call.

the operation new

creates a new object. The object in this case is Lane.

I didn't read through your code too much. However, what you want in LaneTest is

public class LaneTest () {

public static void main (String[] args) {

Lane myLane = new Lane();

myLane.addCar();

}

}

Your object is Lane. The operation you would like to run on it is addCar(). addCar() does not return an addCar() either. It returns a 2D array.

Also, try to stay away from while (bool == 1). That can get you in a lot of trouble.

Message was edited by:

kdajani

kdajania at 2007-7-12 8:55:43 > top of Java-index,Developer Tools,Java Compiler...