Pseudocode Problems

1. Study the method below. The code functions correctly. Make any changes you think would make the code easier to read, understand, or maintain. Then write the documentation comments for the method, following the pseudocode standard. Also write a brief method header comment.

	/**
	 *  
	 */
	public void updateScore()
	{
		String str = "Score\tName\n";

		for (int i=0; i<players.size(); i++)
		{

			str += ((Player) players.get(i)).toString() + "\n";
		}

		gui.setPlayersList(str);
	}


2. Write the documentation comments for the method below, following the pseudocode standard.
    /**
     * Return an array of winners.  It looks at all the scores, and gets
     * the players
     * with the highest score.
     *
     * @return  an array of players representing the winners
     */
    public Player[] getWinners()
    {
        Player player;

        Vector winners = new Vector();

        winners.add(players.get(0));

        for (int i=1; i<players.size(); i++)
        {
            player = (Player) players.get(i);

            if (player.getScore() > ((Player) winners.get(0)).getScore())
            {
                winners = new Vector();
                winners.add(player);
            }

            else if (player.getScore() == ((Player) winners.get(0)).getScore())
            {
                winners.add(player);
            }
        }

        Player wins[] = new Player[winners.size()];
        winners.toArray(wins);

        return wins;
    }

3. The example below shows some poorly written pseudocode.  Rewrite the algorithm so it is clear and correct.  Feel free to make whatever assumptions seem appropriate about the requirements or high level design.


/**
* Deal all the cards in the deck to the n players in the game.
* Each player in turn is dealt a card until the deck is empty.
*/
public void distributeCards()

WHILE deck is not empty

    Assign card at start of the deck to each player

    Decrement number of cards on the deck

END WHILE

Set each player's hand with distributed cards


Solution (for instructor only)