Objective: Create a Karel J Robot program which uses for and while loops
Complete the program below which has a robot walk along the ground looking for mine shafts, when a mine is found the robot digs to the bottom and picks up all beepers along the way. The robot then climbs back up and moves forward. The robot must be able to find all mines in a 10 by 10 world. Start the robot from the position indicated below. The robot must be able to handle mines in any location and any depth.
Below is a before and after example of a world with mines, however MineBot should be able to find mines in any location.
MineBot before exploring mines.
MineBot after exploring mines.
/** * MineBot */ import kareltherobot.*; class MineBot extends Robot implements Directions { // keeps track of the total number of beepers picked up private int beepsPicked = 0; /*** 0 parameter constructor ***/ public MineBot() { super(7, 1, North, 100); } /*** 4 parameter constructor ***/ public MineBot(int street, int avenue, Direction dir, int numberOfBeepers) { super(street, avenue, dir, numberOfBeepers); } /** * The digDown method moves a robot, facing any direction, * down a mine shaft and picks up all beepers along the way */ public void digDown() { /************** complete the code ***************/ } /** * The climbUp method should move a robot, facing any direction, * from the bottom of a hole up to street level. */ public void climbUp() { /************** complete the code ***************/ } /** * moveEast should move a robot, facing any direction, east one block */ public void moveEast() { /************** complete the code ***************/ } /** * The exploreMines method explores the mine world by repeating * methods: digDown, climbUp, and moveEast a given number of times. * * Then it puts down the total number of beepers it * picked up along the way. */ public void exploreMines(int numMines) { /************** complete the code ***************/ } /****** add additional methods as needed, such as: ******/ /****** faceEast, faceNorth, faceSouth ... ******/ }
/********************************************************* * TESTER PROGRAM * This Code is Complete!!! **********************************************************/ import kareltherobot.*; public class MineBotTester implements Directions { public static void showWorld() { World.setVisible(true); // Makes world display World.setDelay(1); // pause for 1/100 second between robot actions World.readWorld("mine.wld"); // Define world } public static void main(String args[]) { showWorld(); MineBot Digger = new MineBot(); Digger.exploreMines(9); } }