public void bombAllEnemies() { while (hasMoreBombs()) bombNextEnemy(); } private void bombNextEnemy() { int row = 0; while (!isEnemyAhead()) { down(); row++; } up(); row--; forward(); dropBomb(); while (row > 0) { up(); row--; } } public static int countCookies(CookieJar jar) { CookieJar temp = new CookieJar(); int count = 0; //move all cookies from jar to temp while (!jar.isEmpty()) { temp.addCookie(jar.removeCookie()); count++; } //move all cookies back to jar while (!temp.isEmpty()) jar.addCookie(temp.removeCookie()); return count; }