Advertisement
jdalbey

Skeleton of Hot Potato class

Oct 13th, 2013
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1. /** A simulation of the game of Hot Potato.
  2.  * @author jdalbey
  3.  * @version 2013.10.12
  4.  */
  5. public class HotPotato
  6. {
  7.     private StringBuilder losers; // the names of the losers, in order.
  8.     private int winner; // the number of the winner
  9.    
  10.     /** Construct a Hot Potato game.
  11.      * @post winner is zero, losers is empty
  12.      */
  13.     public HotPotato()
  14.     {
  15.         winner = 0;
  16.         losers = new StringBuilder();
  17.     }
  18.    
  19.     /** Accessor to the winner, the last person removed from the game.
  20.      *  @return int the number of the winning player, or zero if no game
  21.      *  has been played.
  22.      */
  23.     public int getWinner()
  24.     {
  25.         return winner;
  26.     }
  27.     /** Accessor to the names of the losers.
  28.      * @return String the names of the losers, in order they lost.
  29.      * One blank follows each name.  Returns an empty string if no
  30.      * game has been played.
  31.      */
  32.     public String getLosers()
  33.     {
  34.         return losers.toString();
  35.     }
  36.     /** Determine the outcome of a round of Hot Potato.
  37.      * @param tableSize the number of people at the table
  38.      * @param skipDistance the number of people skipped at each pass
  39.      * of the potato.
  40.      */
  41.     public void playGame(int tableSize, int skipDistance)
  42.     {
  43.     }
  44.  
  45.     /** Application entry point.  
  46.      * @param args number of people at the table, and skip distance
  47.      */
  48.     public static void main(String[] args)
  49.     {
  50.         /* number of people at the table (N)*/
  51.         int tableSize = Integer.parseInt(args[0]);
  52.  
  53.         /* The number of people passed during each round (M) */
  54.         int skipDistance = Integer.parseInt(args[1]);
  55.        
  56.         // Echo the input parameters
  57.         System.out.print("Table size: " + tableSize);
  58.         System.out.println("\tskip distance: " + skipDistance);
  59.  
  60.         // Play a game with the specified parameters
  61.         HotPotato hp = new HotPotato();
  62.         hp.playGame(tableSize, skipDistance);
  63.         // Report the results
  64.         System.out.println("In order, the losers are: " + hp.getLosers());
  65.         System.out.println("The winner is: " + hp.getWinner());        
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement