User Tools

Site Tools


a_task_for_two_robots

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.

API

/** 
 * 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.txt · Last modified: 2019/08/18 12:36 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki