1. /** Convert user's choice of direction to compass degrees and do the computation. */ public double doComputation(int dir) { CASE dir OF 0: RETURN bigCalc(0); 1: RETURN bigCalc(90); 2: RETURN bigCalc(180); 3: RETURN bigCalc(270); OTHERS: RETURN 0; ENDCASE } 2. /* Shuffle the cards */ private void shuffle(Card[] cardlist) { FOR size = cardlist length to 1 by -1 LOOP FOR index 1 to size LOOP IF cardlist[index] greater than cardlist[index + 1] THEN SWAP cardlist[index] with cardlist[index + 1] END IF END LOOP END LOOP } 3. /** Call the model to make the move for the selected button */ public void actionPerformed(ActionEvent evt) { SET sourceButton to evt.getSource() FOR each button in buttonList LOOP IF sourceButton = button THEN SET name = CALL button.getName() RETURNS String END IF END LOOP CALL game.move(name) } 4. /** Insert a name into the proper position in the list */ public void insert(String name) { ADD name to end of list CALL Collections.sort WITH list } 5. /** Assign the number of points to the selected color */ public void lookupPoints(String color) { SET names to array of "red","blue","green","yellow","orange","violet" SET points to array of 1,3,6,8,10,15 FOR index IN 1 to names.length LOOP IF color = names[index] THEN return points[index] END IF END LOOP } 6. /* This controller class updates the accordion model class when a user * interacts with either the console view or the swing GUI view */ public class AccordionController implements ActionListener { private AccordionModel model; private boolean cardSelected = false; private String card1; private String card2; /* This function notifies/updates the model when a user clicks on 2 * cards, prompting a move in the swing UI version of the game */ public void actionPerformed(ActionEvent evt) { SET action to evt.getActionCommand() IF action = "A" THEN IF cardSelected THEN IF card1 not "A" THEN card2 = "A"; model.setCard(card1, card2); cardSelected = false; ELSE PRINT "Invalid Move!" cardSelected = false; END IF ELSE card1 = "A"; cardSelected = true; END IF ELSE IF action = "B" THEN IF cardSelected THEN IF card1 not "B" THEN card2 = "B"; model.setCard(card1, card2); cardSelected = false; ELSE PRINT "Invalid Move!" cardSelected = false; END IF ELSE card1 = "B"; cardSelected = true; END IF ELSE IF action = "C" THEN IF cardSelected THEN IF card1 not "C" THEN card2 = "C"; model.setCard(card1, card2); cardSelected = false; ELSE PRINT "Invalid Move!" cardSelected = false; END IF ELSE card1 = "C"; cardSelected = true; END IF ELSE IF action = "D" THEN IF cardSelected THEN IF card1 not "D" THEN card2 = "D"; model.setCard(card1, card2); cardSelected = false; ELSE PRINT "Invalid Move!" cardSelected = false; END IF ELSE card1 = "D"; cardSelected = true; END IF ELSE IF action = "E" THEN IF cardSelected THEN IF card1 not "E" THEN card2 = "E"; model.setCard(card1, card2); cardSelected = false; ELSE PRINT "Invalid Move!" cardSelected = false; END IF ELSE card1 = "E"; cardSelected = true; END IF ... (twenty-one more times) } } SOLUTIONS 1. dir * 90 2. Collections.shuffle() 3. CALL sourceButton.getName() 4. list.insert(name) 5. map.get(color) 6. Move to Model: IF card1 not action THEN card2 = action move(card1,card2)