Hi. I'm in a Java class at harvard, and they gave us this assignment to create a function moveKiloMile(); , which moves an on-screen robot 1000 units. We can declare the function by using a function moveMile(); , which moves the robot 8 units. Below is the code that I wrote. I'm trying to find out how to do the kilomile function without using a loop, since the professor says that its relatively short.
class Mover extends UrRobot
{
void turnAround()
{
turnLeft();
turnLeft();
}
void moveMile()
{
move();
move();
move();
move();
move();
move();
move();
move();
}
void moveKiloMile()
{
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
moveMile();
}
main
{
Mover Karel = new Mover (1, 1, East, 0);
Karel.turnAround();
Karel.turnAround();
moveMile();
moveKiloMile();
}
}
To download the program we created this in, visit http://www.fas.harvard.edu/~libs111 and click the "Karal" button on the left column.
Thanks!
Ian