nels 105000.80 mary 20000.50 frank 18153.33 nancy 91868.73 michelle 20858Use a Scanner object, not a Console object, to read input because the TAs may redirect stdin in order to test your program. You may assume that the input is error free.
average salary = 51,176.27 nels 105,000.80 true mary 20,000.50 false frank 18,153.33 false nancy 91,868.73 true michelle 20,858.00 false
In the game of golf, players can rank themselves with a handicap. This is a number that basically tells you how good you are at the game. The lower your handicap, the better you are.
The US Golf Association has a very lengthy description of how you calculate a handicap. It may be found at http://www.usga.org/Handicapping.aspx?id=7792 if you're interested. I'm going to simplify it a bit. Here is how you calculate a handicap for a golfer:
where score is the player's score for the round, rating is the rating of the course on which the round was played, and slope is the slope of the course on which the round was played.
Your strategy for solving this problem should be as follows:
Use Java's GregorianCalendar class (java.util.GregorianCalendar) to store dates. They support the compareTo method, so they can be the key you use in the tree. Here are a couple things you should know about the Gregorian Calendar class:
GregorianCalendar date = new GregorianCalendar(1964, 1, 3);This numbering scheme can cause you grief if you're not careful. For example, if you try to enter Dec. 15, 1999 as
date = new GregorianCalendar(1999, 12, 15);Java will convert it to January 15, 2000, thinking that you meant to "roll over" to a new year with the 12. Hence when you parse the score files, make sure you subtract 1 from the month when you create a date object.
import java.util.GregorianCalendar; import java.text.SimpleDateFormat; ... GregorianCalendar date = new GregorianCalendar(1964, 1, 3); SimpleDateFormat dateFormatter = new SimpleDateFormat("MM-dd-yyyy"); String printableDate = dateFormatter.format(date.getTime()); System.out.println(printableDate);This outputs 02-03-1964, which you might find useful if you are trying to print dates to help you debug your program. Note the MM for months. You would think that mm would work but it doesn't (try for yourself).
Your Job
Your job is to write the program handicap.java. It should take two command line arguments:
java jar handicap.jar score-file course-fileThe score-file is a file that contains scores. Each line of this file is in the following format:
Month Day Year Name Score CourseMonth is a number between 1 and 12. Day is a number between 1 and 31. You do not have to error check for legal month/day combinations (i.e. don't worry about 2/30). Year is the year (i.e. 1999, 2000). Name is a one-word name of a golfer, and Score is an integer score. Course is the name of a course, and may contain any number of words separated by white space. Although course is the last part of the line, you cannot assume that there will be only one space between each of the names in the course. Hence you will need to iterate through each of the names and concatenate them together, each separated by a space. The scores can be in any order, and there can be any number of golfers in the score file.
There are example score files in /home/bvz/courses/302/labs/lab3:
Course Three Ridges -- White Tees Rating 69.3 Slope 119 Par 72 |
This says that there is a course that's called ``Three Ridges -- White Tees'' with a rating of 69.3 and a slope of 119. You ignore the ``Par'' line, and the blank line after the ``Par'' line.
In both files (scores and courses) you should create a string for a course that is composed of each word separated by a space. For example, the following course specifications should be equivalent:
Course Three Ridges -- White Tees Course Three Ridges -- White Tees
Now, your program must read in both of these files. You may assume that they contain no errors and that they contain at least 20 scores for each golfer. Then print out the golfers and their handicaps, ordered by handicap (lowest first). Print out the handicap first (padded to 5 characters and two decimal places), and then the golfer's name.
For example:
UNIX> java -jar handicap.jar score1 courses 14.31 Jim UNIX> java -jar handicap.jar score2 courses 3.70 Phil 14.31 Jim UNIX> java -jar handicap.jar score3 courses 3.70 Phil 14.31 Jim UNIX> java -jar handicap.jar bigscore courses 2.58 Tiger 8.26 Phil 8.31 Sergio 9.63 David 9.77 Anika 10.12 Jose 18.12 Ernie 18.21 Colin 18.50 John 18.88 Se-Ri 39.55 KarrieA working executable is available at ~bvz/cs302/labs/lab3/handicap (it's a C++ implementation, not a Java implementation). If you set the environment variable PRINTDIFFS to be "yes", then the program will also print out each golfer's differential and date number (defined in step 4 below) or each score. You can use this to test yourself in case your computations do not seem to match those here. Note, you do not have to implement this feature. It is just included it so that you can help test your own code.
UNIX> setenv PRINTDIFFS yes UNIX> handicap score1 courses Jim Dnum: 743660 Differential: 17.76 Dnum: 743661 Differential: 17.76 Dnum: 743691 Differential: 14.91 Dnum: 743693 Differential: 14.91 Dnum: 743722 Differential: 17.76 Dnum: 743725 Differential: 17.76 Dnum: 743753 Differential: 14.91 Dnum: 743757 Differential: 14.91 Dnum: 743784 Differential: 17.76 Dnum: 743789 Differential: 17.76 Dnum: 743815 Differential: 14.91 Dnum: 743821 Differential: 14.91 Dnum: 743846 Differential: 17.76 Dnum: 743853 Differential: 17.76 Dnum: 743877 Differential: 14.91 Dnum: 743885 Differential: 14.91 Dnum: 743908 Differential: 17.76 Dnum: 743939 Differential: 14.91 Dnum: 743970 Differential: 17.76 Dnum: 744001 Differential: 14.91 14.31 Jim UNIX> setenv PRINTDIFFS no UNIX> handicap score1 courses 14.31 Jim UNIX>
Please submit the following two files: