/* * File: Section1.java * -------------------------------- * Karel checks a punch card for half punched holes and cleans * those up. holes where the middle thingy is still existend * are considered as valid. */ import stanford.karel.*; public class Section1 extends SuperKarel { /** * Specifies the program entry point. */ public void run() { while( frontIsClear() ) { move(); checkAndCleanHole(); move(); } } private void checkAndCleanHole() { /* This Method checks the current hole Karel is standing in and * cleans it up completly IF required. * * pre-condition: karel sitting in the middle of a hole (on Y=3), * facing EAST * * post-condition: karel sitting in the middle of a hole (on Y=3), * facing EAST */ if( noBeepersPresent() ) { cleanLeft(); cleanRight(); } } private void cleanLeft() { /* This Method cleans the LEFT side of a Hole * * pre-condition: karel sitting in the middle of a hole (on Y=3), * facing EAST * * post-condition: karel sitting in the middle of a hole (on Y=3), * facing EAST */ turnLeft(); move(); pickAllBeepers(); turnAround(); move(); turnLeft(); } private void cleanRight() { /* This Method cleans the RIGHT side of a Hole * * pre-condition: karel sitting in the middle of a hole (on Y=3), * facing EAST * * post-condition: karel sitting in the middle of a hole (on Y=3), * facing EAST */ turnRight(); move(); pickAllBeepers(); turnAround(); move(); turnRight(); } private void pickAllBeepers() { /* This Method picks up ALL Beepers at Karels actual position */ while( beepersPresent() ){ pickBeeper(); } } }