public class lab2 { public static void twodot44 () { Vic vicar; // declare a Vic reference vicar = new Vic(); // set vicar to refer to a new Vic object if (vicar.seesCD()) { // is there a CD in the 1st slot? vicar.takeCD(); // if so place it on the stack } else { // if there isn't a cd in the first slot vicar.moveOn(); // move to the next slot if (vicar.seesCD()) { // is there a CD in the 2nd slot? vicar.takeCD(); // if so place it on the stack } else { // if there isn't a cd in the 1st or 2nd slot vicar.moveOn(); // move on to the next slot if (vicar.seesCD()) { // is there a CD in the 3rd slot? vicar.takeCD(); // if so place it on the stack } else { /* if there isn't a cd in the first 3 slots, we are guaranteed by the precondition that there must be one in the 4th slot! */ vicar.moveOn(); vicar.takeCD(); } // close the else situation where the first 3 slots are empty } // close the else situation where the first 2 slots are empty } // close the else situation where the first slot is empty } // end of twodot44 public static void twodot45-1() { Vic vicar; vicar = new Vic(); boolean has2slots = false; if (vicar.seesCD()) { vicar.moveOn(); if (vicar.seesCD()) { has2slots = true; vicar.backUp(); } else { vicar.moveOn(); has2slots = vicar.seesCD(); vicar.backUp(); vicar.backUp(); } } else { vicar.moveOn(); if (vicar.seesCD()) { vicar.moveOn(); has2slots = vicar.seesCD(); vicar.backUp(); vicar.backUp(); } } if (has2slots) { if ( !vicar.seesCD()){ // design step 1 vicar.moveOn(); // design step 1a vicar.takeCD(); vicar.moveOn(); // design step 1b } else // design step 2 { vicar.takeCD(); // design step 2a vicar.moveOn(); // design step 2b if ( ! vicar.seesCD()) // design step 2c vicar.moveOn(); } vicar.takeCD(); // design step 3 // end of modified 2.11 code } } public static void twodot45() { // find out if there exists at least 2 cds in the first 3 slots Vic vicar; vicar = new Vic(); if (vicar.seesCD()) { // we have a cd in slot 1 vicar.moveOn(); if (vicar.seesCD()) {// we have a cd in slot 1 & 2... thus we have the needed 2 cds // move back a slot to bring us back to the start vicar.backUp(); // start of modifed 2.11 code if ( !vicar.seesCD()){ // design step 1 vicar.moveOn(); // design step 1a vicar.takeCD(); vicar.moveOn(); // design step 1b } else // design step 2 { vicar.takeCD(); // design step 2a vicar.moveOn(); // design step 2b if ( ! vicar.seesCD()) // design step 2c vicar.moveOn(); } vicar.takeCD(); // design step 3 // end of modified 2.11 code } // end of situation where the 1st two slots are filled else { // first slot is full, but 2nd is not vicar.moveOn(); // check out slot 3 if (vicar.seesCD()) { // if it's full, we have 2 cds // move back 2 slots to get us back to the start vicar.backUp(); vicar.backUp(); // start of modified 2.11 code if ( !vicar.seesCD()){ // design step 1 vicar.moveOn(); // design step 1a vicar.takeCD(); vicar.moveOn(); // design step 1b } else // design step 2 { vicar.takeCD(); // design step 2a vicar.moveOn(); // design step 2b if ( ! vicar.seesCD()) // design step 2c vicar.moveOn(); } vicar.takeCD(); // design step 3 // end of modified 2.11 code } // end of case where the 1st and last slot are full } // end of the case where the 1st slot is full, but the 2nd is not } // end of the case where the 1st slot is full else { // 1st slot is empty vicar.moveOn(); // move to slot 2 if (vicar.seesCD()) {// if we see a filled slot 2 we then have 1 cd vicar.moveOn(); // move to slot 3 if (vicar.seesCD()) { // 2nd and 3rd slot are full // move back to the first spot vicar.backUp(); vicar.backUp(); // start of modified 2.11 code if ( !vicar.seesCD()){ // design step 1 vicar.moveOn(); // design step 1a vicar.takeCD(); vicar.moveOn(); // design step 1b } else // design step 2 { vicar.takeCD(); // design step 2a vicar.moveOn(); // design step 2b if ( ! vicar.seesCD()) // design step 2c vicar.moveOn(); } vicar.takeCD(); // design step 3 // end of modified 2.11 code }// end of case where the 2nd and 3rd slots are full } // end of case where the 2nd slot is full but the 1st is not } // end of the case where the 1st slot is empty } // end of twodot45 } // end of the lab2 class