I need to make a second array I think. the task is this...Randomize the numbers that you are sorting between 1 and 6. Repeated numbers are not allowed though. Hint: Place 1 through 6 in an array of integers first. Then randomly pick two elements in the array and swap them. Do so six times. But after a long weekend of trying and burning out my brain on it I have nothing.
Any help would be awesome
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Sets up the SortGrid world. This includes creating all nodes
* and numbers, connecting the nodes up and placing them in the world.
*
* @author Joseph Lenton
*/
public class SortGrid extends World
{
private static final int WIDTH = 800; // Lab 9, wider screen
private static final int HEIGHT = 600;
private static final int NUMBER_Y = 50;
private static final int NUMBER_PADDING = 100;
private static final int NUMBER_X = 150;
private static final int NUM_POSITIONS = 6; // Lab9, more numbers
/**
* Creates and sets up the SortGrid world ready to be run.
*/
public SortGrid()
{
super( WIDTH, HEIGHT, 1 );
// end nodes
End[] ends = new End[ NUM_POSITIONS ];
for ( int i = 0; i < ends.length; i++ ) {
End end = new End();
ends[i] = end;
addObject( end, NUMBER_X + NUMBER_PADDING*i, HEIGHT-NUMBER_Y );
}
// lab 9, more nodes
final int leftX = WIDTH/4;
// create the network node
Node fithRowNode = new Node();
fithRowNode.setDestinations(ends[2], ends[3]);
addObject( fithRowNode, leftX + NUMBER_PADDING*2 , 450 );
Node[] fourthRow = new Node[2];
for ( int i = 0; i < fourthRow.length; i++ ) {
Node node = new Node();
fourthRow[i] = node;
addObject( fourthRow[i], 300 + NUMBER_PADDING*i*2, 375 );
}
fourthRow[0].setDestinations(ends[1], fithRowNode);
fourthRow[1].setDestinations(fithRowNode, ends[4]);
Node[] thirdRow = new Node[3];
for ( int i = 0; i < thirdRow.length; i++ ) {
Node node = new Node();
thirdRow[i] = node;
thirdRow[i].setDestinations(fourthRow[0], fourthRow[1]);
addObject( thirdRow[i], leftX + NUMBER_PADDING*i*2, 300 );
}
thirdRow[0].setDestinations(ends[0], fourthRow[0]);
thirdRow[1].setDestinations(fourthRow[0], fourthRow[1]);
thirdRow[2].setDestinations(fourthRow[1], ends[5]);
Node[] secondRow = new Node[3];
for ( int i = 0; i < secondRow.length; i++ ) {
Node node = new Node();
secondRow[i] = node;
//secondRow[i].setDestinations(thirdRow[0], thirdRow[1]);
addObject( secondRow[i], leftX + NUMBER_PADDING*i*2, 225 );
}
secondRow[0].setDestinations(thirdRow[0], thirdRow[1] );
secondRow[1].setDestinations(thirdRow[0], thirdRow[2] );
secondRow[2].setDestinations(thirdRow[1], thirdRow[2] );
Node[] firstRow = new Node[3]; // closest to top of screen
for ( int i = 0; i < firstRow.length; i++ ) {
Node node = new Node();
firstRow[i] = node;
//firstRow[0].setDestinations(secondRow[0], secondRow[1] );
addObject( firstRow[i], leftX + NUMBER_PADDING*i*2, 150 );
}
firstRow[0].setDestinations(secondRow[0], secondRow[1] );
firstRow[1].setDestinations(secondRow[0], secondRow[2] );
firstRow[2].setDestinations(secondRow[1], secondRow[2] );
final int[] randomNums = {6, 5, 4, 3, 1, 2};
final Number[] numbers = new Number[ NUM_POSITIONS ];
// make the numbers visable
for ( int i = 0; i < NUM_POSITIONS; i++ ) {
final Number number = new Number( randomNums[i] );
final int x = NUMBER_X + NUMBER_PADDING*i;
final int y = NUMBER_Y;
numbers[i] = number;
addObject( number, x, y );
addObject( new Start(), x, y );
}
// set the number destinations
numbers[0].setDestination( firstRow[0] );
numbers[1].setDestination( firstRow[0] );
numbers[2].setDestination( firstRow[1] );
numbers[3].setDestination( firstRow[1] );
numbers[4].setDestination( firstRow[2] );
numbers[5].setDestination( firstRow[2] );
// paint ordering
setPaintOrder(
Number.class,
Node.class,
Position.class,
Start.class
);
}
}


