how can i make dis program work

April 9, 2009 at 16:17:11
Specs: Windows XP
Write a JAVA program that generates a ‘random” (drunk) walk across a 10 X 10 array. Initially the array will contain all periods(‘.’);

The program must randomly ‘walk’ from element to element – always going up, down, right, or left (no diagonal) by one element.

The elements ‘visited’ will be labeled by the letters ‘A’ through ‘Z’ in the order visited.

To determine you direction to move, use the random() method to generate a random integer
double rand = random();
Convert the random integer to a number 0~3 (hint: use the mod %)

If the number generated is a:
0 – move up (north)
1 – move right (east)
2 – move down (south)
3 – move left (west)
If the spot you are trying to move to is already occupied by a letter (has been visited), try the next spot. In other words

Random number is a 0 – check N, E, S, W
1 – check E, S, W, N
2 – check S, W, N, E
3 – check W, N, E, S

Keep within the array (check array bounds before moving)

If you hit a point where you cannot move, stop and print the array
If you get to the letter ‘Z’, stop and print the array

Ask for the user to enter the initial row and column on which to start.
Validate that row and column entered are valid (within the array)

Beginning program included. Example output also included
i have this much so far_____________________
import java.lang.Math.*;

class DrunkWalker
{

/*****************
* data items
******************/
private static char ch[][] = new char[10][10];
private static int randNSEW;
private static int stopCode = 0;
private static int row = 0;
private static int col = 0;
private static int alphaIndex = 0;


public static void main(String args[])
{
row = 4;
col = 6;

loadArray();
printArray();

while(stopCode != 1)
{
getRand();
switch(randNSEW)
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
default: break;
} // end switch

if(alphaIndex == 26)
{
stopCode = 1;
}
} // end while loop

} // end main
public static void loadArray()
{
int row;
int col;
for(row=0; row<10; row++)
{
for(col=0; col<10; col++)
{
ch[row][col] = '.';
}
}
}// end loadArray

public static void printArray()
{
int row;
int col;
for(row=0; row<10; row++)
{
System.out.println();
for(col=0; col<10; col++)
{
System.out.print(ch[row][col]);
}
}
System.out.println();
}// end printArray
public static void getRand()
{
int x100 = 0;
double randomNum = 0.0;
randomNum = Math.random();
x100= (int)(randomNum * 100);
randNSEW = x100 % 4;
}
}


See More: how can i make dis program work

Report •


#1
April 9, 2009 at 20:28:15
can someone plz help with dis program

Report •
Related Solutions


Ask Question