{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

10a-section-1-solutions

# 10a-section-1-solutions - private void removeChad turnRight...

This preview shows page 1. Sign up to view the full content.

Mehran Sahami Handout #10A CS 106A September 30, 2009 Solutions for Section #1 Based on a handout by Eric Roberts /* * File: VoteCountingKarel.java * ---------------------------- * The VoteCountingKarel subclass cleans out the chad from * a ballot as described in the section handout. */ import stanford.karel.*; public class VoteCountingKarel extends SuperKarel { public void run() { while (frontIsClear()) { move(); if (noBeepersPresent()) { removeChad(); } move(); } } /** * Removes any chad from a ballot, which consists of beepers * in the squares to right and left of Karel's current position.
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: */ private void removeChad() { turnRight(); checkPunchCorner(); checkPunchCorner(); turnLeft(); } /** * Removes any chad from the corner in front of Karel. The * precondition is that Karel is facing one of the corners * that represents a punch hole in a ballot; the postcondition * is that Karel is on the same square but facing in the * opposite direction since it has just come out of the hole. */ private void checkPunchCorner() { move(); while (beepersPresent()) { pickBeeper(); } turnAround(); move(); } }...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern