User Tools

Site Tools


a_task_for_two_robots

This is an old revision of the document!


A Task For Two Robots

Karel is at 3rd street and 1st avenue on a corner facing East. There is a beeper at 2nd street and 1st avenue. Jane is at the origin facing East. Karel should pick up the beeper and bring it to Jane. Jane should then pick it up and carry it to 1st street and 4th avenue. The beeper should be placed on this corner.

/** 
 * First.java
 *
 * Title: Chapter 2.9 p. 19			
 * Description:	Move a beeper from position 1,4 to position 3,5
 * @author	Golden Knight	
 * @version	August 19, 2019		
 */
import java.awt.Color;
 
import kareltherobot.*;
public class TaskForTwoRobots implements Directions 
{
	public static void task() 
        {
		Robot karel = new Robot(3, 1, East, 0 , Color.RED);
		Robot jane = new Robot(1, 1, East, 0, Color.BLUE);
		karel.turnLeft();
		karel.turnLeft();
		karel.turnLeft();
 
		karel.move();
		karel.pickBeeper();
		karel.move();
 
		karel.turnLeft();
		karel.putBeeper();
		jane.pickBeeper();
		jane.move();
		jane.move();
		jane.move();
		jane.putBeeper();
		jane.move();
 
		karel.turnOff();
		jane.turnOff();
	}
	// Main method is where the application starts execution
	public static void main(String[] args) 
        {
		World.setDelay(50); 
		World.placeBeepers(2, 1, 1);
		World.setVisible();
 
		task();
	}
}
a_task_for_two_robots.1566139265.txt.gz · Last modified: 2019/08/18 10:41 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki