Question: http://cs.boisestate.edu/~cs121/projects/p3/ This is the full writeup on the assignment is available here. My code is supposed to print out a full array list of all

http://cs.boisestate.edu/~cs121/projects/p3/

This is the full writeup on the assignment is available here. My code is supposed to print out a full array list of all the points my code goes through, but for whatever reason it is only printing out two points and not the full list.

Here is my driver as well as my code, which is everything I have written. There is a code called RandomWalkUnitTester in the writeup above, and the code must pass all of the parameters set by it. I know that when the ArrayList becomes fixed I will be able to fix most of those errors, but I know that the isDone() test is failing and I am not sure as to why. Any help would be appreciated. Thank you so much.

import java.util.Scanner;

public class RandomWalkDriver {

public static void main(String[] args)

{

Scanner scan = new Scanner(System.in);

System.out.println("Please enter your Grid Size:");

int gridSize = scan.nextInt();

while(gridSize <= 1)

{

System.out.println("Error: Please enter a positive integer larger than 1");

gridSize = scan.nextInt();

}

System.out.println("Enter a positive seed integer (0 for no seed):");

long seed = scan.nextLong();

while(seed < 0)

{

System.out.println("Error: Please enter 0 for no seed, or a positive integer");

seed = scan.nextLong();

}

if(seed == 0)

{

RandomWalk newWalk = new RandomWalk(gridSize);

newWalk.createWalk();

System.out.println(newWalk.toString());

}

else {

RandomWalk newWalk = new RandomWalk(gridSize, seed);

newWalk.createWalk();

System.out.println(newWalk.toString());

}

scan.close();

}

}

import java.util.Random; import java.util.ArrayList; import java.awt.Point;

public class RandomWalk implements RandomWalkInterface {

// Instance Variable

// According to rubric, all must be set to private.

private int gridSize;

private Random rand;

private boolean done;

private ArrayList path;

private Point start;

private Point end;

private Point current;

// Constructors

/**

*

* @param gridSize

*/

public RandomWalk(int gridSize)

{

this.gridSize = gridSize;

rand = new Random();

start = new Point(0, gridSize - 1);

current = start;

end = new Point(gridSize - 1, 0);

path = new ArrayList();

path.add(current);

}

/**

* @param gridSize allows the user to input the size of the grid.

* @param seed allows the random walk to be tied to a seed.

*/

public RandomWalk(int gridSize, long seed)

{

this.gridSize = gridSize;

rand = new Random(seed);

start = new Point(0, gridSize - 1);

current = start;

end = new Point(gridSize -1, 0);

path = new ArrayList();

path.add(current);

}

// Methods

public void step()

{

if(current.x == end.x && current.y == end.y)

{

done = true;

}

else{

rand = new Random();

int northEast = rand.nextInt(10) + 1;

if(northEast % 2 == 0)

{

if(current.x != end.x)

{

Point newxCurrent = new Point(current.x + 1, current.y);

path.add(newxCurrent);

current = newxCurrent;

}

else if(current.y != end.y)

{

Point newxyCurrent = new Point(current.x, current.y -1);

path.add(newxyCurrent);

current = newxyCurrent;

}

else

{

done = true;

}

}

else

{

if(current.y != end.y)

{

Point newyCurrent = new Point(current.x, current.y - 1);

path.add(newyCurrent);

current = newyCurrent;

}

else if(current.x != end.x)

{

Point newyxCurrent = new Point(current.x + 1, current.y);

path.add(newyxCurrent);

current = newyxCurrent;

}

else

{

done = true;

}

}

}

}

/**

*

*/

public void createWalk()

{

if(done == false)

{

step();

}

}

/**

* Returns the status of the done boolean.

* @return the status of the done boolean.

*/

public boolean isDone()

{

return done;

}

/**

* Returns the size of the grid.

* @return the size of the grid.

*/

public int getGridSize()

{

return gridSize;

}

/**

* Returns the starting point of the walk.

* @return the starting point of the walk.

*/

public Point getStartPoint()

{

return start;

}

/**

* Returns the ending point of the walk.

* @return the ending point of the walk.

*/

public Point getEndPoint()

{

return end;

}

/**

* Returns the current point of the program.

* @return the current point of the program.

*/

public Point getCurrentPoint()

{

return current;

}

/**

* Returns the path of the RandomWalk.

* @return the path of the RandomWalk.

*/

public ArrayList getPath()

{

return path;

}

/**

* @return the String provided.

*/

public String toString()

{

String result = "";

for(Point p : path)

{

result += "[" + p.x + ", " + p.y + "] ";

}

return result;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!