Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** A simulation of the game of Hot Potato.
- * @author jdalbey
- * @version 2013.10.12
- */
- public class HotPotato
- {
- private StringBuilder losers; // the names of the losers, in order.
- private int winner; // the number of the winner
- /** Construct a Hot Potato game.
- * @post winner is zero, losers is empty
- */
- public HotPotato()
- {
- winner = 0;
- losers = new StringBuilder();
- }
- /** Accessor to the winner, the last person removed from the game.
- * @return int the number of the winning player, or zero if no game
- * has been played.
- */
- public int getWinner()
- {
- return winner;
- }
- /** Accessor to the names of the losers.
- * @return String the names of the losers, in order they lost.
- * One blank follows each name. Returns an empty string if no
- * game has been played.
- */
- public String getLosers()
- {
- return losers.toString();
- }
- /** Determine the outcome of a round of Hot Potato.
- * @param tableSize the number of people at the table
- * @param skipDistance the number of people skipped at each pass
- * of the potato.
- */
- public void playGame(int tableSize, int skipDistance)
- {
- }
- /** Application entry point.
- * @param args number of people at the table, and skip distance
- */
- public static void main(String[] args)
- {
- /* number of people at the table (N)*/
- int tableSize = Integer.parseInt(args[0]);
- /* The number of people passed during each round (M) */
- int skipDistance = Integer.parseInt(args[1]);
- // Echo the input parameters
- System.out.print("Table size: " + tableSize);
- System.out.println("\tskip distance: " + skipDistance);
- // Play a game with the specified parameters
- HotPotato hp = new HotPotato();
- hp.playGame(tableSize, skipDistance);
- // Report the results
- System.out.println("In order, the losers are: " + hp.getLosers());
- System.out.println("The winner is: " + hp.getWinner());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement