Here is my program:
import edu.pace.Robot;
import edu.pace.World;
import javax.swing.JOptionPane;
public class Lab09
{
public static void main(String[] args)
{
String worldname = JOptionPane.showInputDialog("Which world do you want?");
Athlete temp = new Athlete(1, 1, World.EAST, 0);
World.readWorld(worldname);
World.setSize(10, 10);
World.setSpeed(10);
///////////////////////////////////////////////////////////////////////////
int pile1 = 0;
int pile2 = 0;
int pile3 = 0;
int pile4 = 0;
int pile5 = 0;
//////////////////////////////////////////////////////////////////////////
temp.move();
while(temp.nextToABeeper())
{
temp.pickBeeper();
pile1++;
}
temp.move();
while(temp.nextToABeeper())
{
temp.pickBeeper();
pile2++;
}
for(int x = pile1; x > 0; x--)
{
temp.putBeeper();
}
temp.move();
while(temp.nextToABeeper())
{
temp.pickBeeper();
pile3++;
}
for(int x = pile2; x > 0; x--)
{
temp.putBeeper();
}
temp.move();
for(int x = pile3; x > 0; x--)
{
temp.putBeeper();
}
temp.move();
while(temp.nextToABeeper())
{
temp.pickBeeper();
pile4++;
}
temp.move();
for(int x = pile4; x > 0; x--)
{
temp.putBeeper();
}
temp.move();
while(temp.nextToABeeper())
{
temp.pickBeeper();
pile5++;
}
temp.move();
for(int x = pile5; x > 0; x--)
{
temp.putBeeper();
}
}
}
Here is a screenshot of each world:
pile1 - http://xs209.xs.to/xs209/06466/pile1.png
pile2 - http://xs209.xs.to/xs209/06466/pile2.png
pile3 - http://xs209.xs.to/xs209/06466/pile3.png
The robot starts out with 0 beepers btw.
What it's supposed to do: There are three robot worlds I'm supposed to test this on - pile1, pile2, and pile3. This code
works on the first one, but fails on the 2nd and 3rd worlds, which is why I'm coming here for help. The program itself is supposed to shift each beeper pile one to the right, simple enough in idea. I feel like there is something I can do to modify this code, because i'm close to getting it working, but I don't know what I should change, which is why I posted this thread. :p
Thanks for your help,
Ben Katz (10th grade student)
Message was edited by:
B_E_A_N