jdalbey

Golf Pool Class Skeletons

Jan 24th, 2015
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.56 KB | None | 0 0
  1.  
  2. /**
  3.  * GolfPool is an application to find the winner of a golf pool.
  4.  *
  5.  * @author  J. Dalbey
  6.  * @version 0.1
  7.  */
  8. public final class GolfPool
  9. {
  10.  
  11.     /**
  12.      *  Entry point for the application.  Read the data file
  13.      *  name from the command line.
  14.      *  
  15.      *  @param args command line arguments, first argument is
  16.      *  name of data file.
  17.      */
  18.     public static void main(String[] args)
  19.     {
  20.         GolfPool app = new GolfPool();
  21.     }
  22.    
  23.     /** Read data file and compute winner and display results. */
  24.     public void run()
  25.     {
  26.     }
  27. }
  28. import java.util.*;
  29. import java.io.*;
  30. /**
  31.  * AverageList is a list of golfers and their average score for
  32.  * all rounds played.
  33.  *
  34.  * @author  J. Dalbey
  35.  * @version 0.1
  36.  */
  37. public final class AverageList
  38. {
  39.     List<Golfer> list = new ArrayList<Golfer>();
  40.  
  41.     /**
  42.      * Constructor for objects of class AverageList
  43.      */
  44.     public AverageList()
  45.     {
  46.     }
  47.  
  48.     /** Read golf scores from specified Reader, and accumulate
  49.      * the total for each golfer.  Also count the number of scores read
  50.      * for each golfer.
  51.      * @param rdr Reader from which scores will be obtained
  52.      */
  53.     public void readDatafile(Reader rdr)
  54.     {
  55.     }
  56.  
  57.     /** Calculate average for each golfer
  58.      */
  59.     public void computeAverages()
  60.     {
  61.     }
  62.    
  63.     /** Find lowest average in the list.
  64.      * Assumes computerAverages() has been called.
  65.      */
  66.     public void findLowestAverage()
  67.     {
  68.     }
  69.    
  70.     /** Return name of winner
  71.      * @return winner's name
  72.      */
  73.     public String getWinner()
  74.     {
  75.         return "";
  76.     }
  77.    
  78.     /** Return lowest average.
  79.      * @return average of winning golfer
  80.      */
  81.     public double getLowestAverage()
  82.     {
  83.         return 0;
  84.     }
  85.    
  86.     /** Return rounds played by winner
  87.      * @return number of rounds
  88.      */
  89.     public int getRoundsPlayed()
  90.     {
  91.         return 0;
  92.     }
  93.     /** Determine if there is an eligible winner.
  94.      * @return false if no golfer has played three rounds, true otherwise
  95.      */
  96.     public boolean doesWinnerExist()
  97.     {
  98.         return true;
  99.     }
  100.    
  101.     /** For unit testing: accessor to list size */
  102.     int size()
  103.     {
  104.         return list.size();
  105.     }
  106. }
  107.  
  108. /**
  109.  * Golfer is a record of the statistics for a golfer for a month.
  110.  *
  111.  * @author  J. Dalbey
  112.  * @version 0.1
  113.  */
  114. public final class Golfer implements Comparable<Golfer>
  115. {
  116.     final String name;
  117.     private int numberRounds;
  118.     private long totalScore;
  119.     private double averageScore;
  120.    
  121.     /**
  122.      * Constructor for objects of class Golfer
  123.      */
  124.     public Golfer(String name)
  125.     {
  126.         this.name = name;
  127.     }
  128.  
  129.     /**
  130.      * Add one score to total
  131.      * @param roundScore the score to be added to the total
  132.      * @pre roundScore > 0
  133.      */
  134.     public void addScore(int roundScore)
  135.     {    
  136.     }
  137.    
  138.     /**
  139.      * Calculate average score.
  140.      * @pre addScore has been called at least once.
  141.      */
  142.     public void calculateAverage()
  143.     {
  144.     }
  145.    
  146.     /**
  147.      * Compare two golfers.  Lowest average wins,
  148.      * ties go to player with most rounds.
  149.      * @param other golfer to be compared to this one.
  150.      * @return 0 if the two golfers are equal,
  151.      * -1 if this golfer is smaller,
  152.      * +1 if this golfer is larger.
  153.      */
  154.     public int compareTo(Golfer other)
  155.     {
  156.         return 0;
  157.     }
  158.    
  159.     /** Accessors */
  160.     public int getRounds()
  161.     {
  162.         return 0;
  163.     }
  164.     public double getAverage()
  165.     {
  166.         return 0;
  167.     }
  168.    
  169. }
Advertisement
Add Comment
Please, Sign In to add comment