Question: Use Java to 1. Implement an abstract class in Java to produce reusable classes. 2. Develop a program with several classes. 3. Extend the functionality
Use Java to
1. Implement an abstract class in Java to produce reusable classes.
2. Develop a program with several classes.
3. Extend the functionality of existing classes.
4. Develop a program using an Array of object references.
5. Use method calls to perform logic steps involved in calculations.
6. Implement a solution involving polymorphism.
Project Requirements:
1. It turns out that Bowling uses a handicap system similar to golf. In both sports a handicap is used to allow players at different skill levels to compete. The basic objective of Programming Project 3 is to create classes that enable you to calculate player's handicap. The games you will be working with are Golf and Bowling. Both games require adding scores and calculating handicaps. This functionality can be realized by implementing inheritance including an abstract class and polymorphism. Below are the steps we will use to calculate handicaps in both games.
2. NOTE: Your code should ensure all instance field are valid as described in their requirements. If not write an error message to the standard output and continue. Set the field value to 9999. For example, the bowling score must be between 0 and 300(inclusive)(You may use a user defined exception but it isnt required for this project) 3. The Bowling handicap is calculated using the following steps:
1. Calculate the average of the bowlers last 5 scores.
2. Calculate the difference between the established base bowling average which in our case is 200 and the bowlers average.
3. Calculate the final handicap by taking 80% of the results of step 2.
4. Example 1. The bowlers last 5 scores average is 180. 2. 200 - 180 = 20. 3. 80% of 20 is 16.
4. The bowlers handicap is 16 so we would add 16 to his next score. Note if the bowler's average is higher than 200, there handicap would be subtract from their next score.
4. The Golf handicap index is calculated using the following steps:
1. Calculate the stroke differential of each the last 10 scores.
1. Stroke differential is calculated using the following formula:
2. Differential = (score - courseRating) x (113 / courseSlope): round to 2 decimal places.
2. Calculate the average of the 5 lowest differentials from step 1.
3. Calculate the final handicap by taking 96% of the results of step 2. round to 2 decimals places
4. Example 1. The golfers last 10 differentials are: 10.2, 11.5, 12.0, 9.8, 8.2, 9.9, 10.0 15.4, 12.3. 9.5.
2. The lowest 5 differentials are: 9.8, 8.2, 9.9, 10.0, 9.5
3. Average of 5 lowest differentials is: 47.4 / 5 = 9.48 4. 96% of 9.48 is 9.1
5. The handicap index is 9.1. Note that like bowling a golfer handicap can be a negative number.
5. The Player Class (abstract class)
1. Instance Variables
1. name - A String representing the player's name
2. IDNum- A unique integer that identifies each player
2. Static Variable - int nextIDNum - starts at 1000 and is used to generate the next Player's IDNum
3. Methods 1. Constructor - sets name and uses the static variable nextIDNum to retrieve the next available ID number.
2. Constructor - default constructor, sets all instance field to a default value.
3. Accessor and Mutator methods for instance variables.
4. toString - returns a neatly formatted String representing the player's information.
5. calculateHandicap - abstract method that returns a double representing the players handicap
6. Golfer Class - Must extend the Player abstract class (listed above)
1. This is a class designed to represent a golfer including his name, home course, id number and an Array of Score Objects. Remember part of being a strong programmer is being flexible enough to learn about new domains, you don't have to be a golfer or a doctor or a banker to write application in those domains.
2. The array will be handled as a partially filled array.
3. Instance Variables
1. homeCourse - A String representing the golf course where the player's handicap is keep.
2. numScores the number of score objects in the Array (Partially Filled Array)
3. scores an Array - stores all the golfer's scores as Score objects. Assume no more than 10 scores. (NOTE: MUST USE AN ARRAY, CANNOT USE ANY OTHER TYPE OF JAVA COLLECTION OBJECT)
4. Methods
1. Constructor - sets name and homeCourse from parameters and uses the static variable nextIDNum to retrieve the next available ID number. Creates Array.
2. Constructor - default constructor, sets all instance field to a default value. Creates Array.
3. Note: that Name and IDnum are stored in the Player class.
4. Accessor and mutator methods for all variables. NOTE Mutator method for IDNum should use the static variable nextIDNum. Mutator method should be used to set all instance fields
5. calculateHandicap - that returns a double representing the golfers current handicap index. (Player's class abstract method)
6. addScore - create a Score object from the parameters that represent the course, course rating, course slope, date and score. Adds the newly created Score object to the Array of Scores. (See Score object below)
7. deleteScore - delete a score from the Array based on score date, Assume only one score per day. Returns true if score found and deleted, false if not found.
8. getScore - returns a score object based on the score date. If not found returns null;
9. findScore - private method given a parameter representing the score's date, returns the Array index of a score. (Use in deleteScore and getScore). Return constant NOTFOUND if not found, NOTFOUND is set to -1;
10. toString - returns a nicely formatted string of a Golfer's information including their handicap and all their scores. Use the Score toString method to assist. It should looks something like
11. The toString methods return should be format add the current handicap to the output.
See Bowler class for an example.
John Smith ID number: 1234 Home Course: Bay Hill CC Handicap: 7.8 Score Date Course Course Rating Course Slope 75 6/3/12 Bay Hill CC 69.5 123 77 7/23/12 AC Read 70.4 128
1. course - the specific place where golf is played.
2. score- The number of strokes taken during a round (18 holes) course rating - indicates the evaluation of the playing difficulty of a course for a scratch golfer (zero handicap) under normal course and weather conditions. It is expressed as strokes taken to one decimal place, and is based on yardage and other obstacles to the extent that they affect the scoring ability of a scratch golfer.
3. course slope - indicates the measurement of the relative difficulty of a course for players who are not scratch golfers. The lowest Slope Rating is 55 and the highest is 155. A golf course of standard playing difficulty has a Slope Rating of 113.
2. Instance Variables
1. score - an int representing a 18 hole score, it must be between 40 and 200 (inclusive)
2. date - a String representing the date in format mm/dd/yy
3. course Course object see below
3. Methods
1. Constructor - sets all instance fields from parameters
2. Default Constructor - sets all instance fields to a default value.
3. Accessor and mutator methods for all instance variables. Mutator method should be used to set all instance fields
4. toString - returns a nicely formatted String that contains the score and its instance fields that looks something like: 75 6/3/12 Bay Hill CC 69.5 123
8. The Course class
1. Instance Variables
1. courseName - a String representing the name of the course.
2. courseRating - a double representing the course rating, it must be between 60 and 80. (inclusive).
3. courseSlope - an int representing the course slope, it must be between 55 and 155 (inclusive).
2. Methods
1. Constructor - sets all instance fields from parameters
2. Default Constructor - sets all instance fields to a default value.
3. Access and mutator methods for all instance variables. Mutator method should be used to set all instance fields
4. toString - returns a nicely formatted String that contains its instance fields such as: Bay Hill CC 69.5 123
9. The Bowler Class - Must extend the Player class listed below
1. Instance Variables 1. teamName - A String representing the bowler's team.
2. Array of BowlerScore objects - stores all the bowler's scores. The array's size can be set to 10. (Partially filled array)
3. numScores the number of score objects in the Array (Partially Filled Array)
2. Methods
1. Constructor - sets name and teamName from parameters and uses the static variable nextIDNum to retrieve the next available ID number. Creates Array.
2. Constructor - default constructor, sets all instance field to a default value. Creates Array.
3. A calculateHandicap method, that returns a double representing the golfers current handicap. (Player's class abstract method)
4. Access and mutator methods for all variables. NOTE Mutator method for IDNum should use the static variable nextIDNum. Mutator method should be used to set all instance fields 5. addScore - receives a BowlerScore object and adds it to the Array of BowlerScores
. 6. toString - returns a nicely formatted String that contains its instance fields: John Smith ID number: 1234 Team Name: Waffle House Current Handicap: 16 Score Date Lane 139 6/3/14 Cordova Lanes 145 7/23/14 Felton Lanes 10.
The BowlerScore Class
1. Instance Variables
1. laneName - a String representing the name of the lane
2. score - an int representing a game's score, it must be between 0 and 300 (inclusive), The score is the gross score, without adding or subtracting the handicap.
3. date - a String representing the date in format mm/dd/yy
2. Methods
1. Constructor - sets all instance fields from parameters
2. Default Constructor - sets all instance fields to a default value.
3. Access and mutator methods for all instance variables. Mutator method should be used to set all instance fields
4. toString - returns a nicely formatted String that contains the score and its instance fields 139 6/3/12 Cordova Lanes 11.
The PlayerTester
1. This class should consist of a main method that tests all the methods in each class, either directly by calling the method from the Tester or indirectly by having another method call a method.
2. Players, Golf Course and Score information will be read from a file. A sample file is provided that shows, use this file format to aid in grading. Using file processing makes entering and testing program with data sets much more efficient.
3. The file created should include valid and invalid data that fully tests the application. Simple text file process is covered in slides named TextFileProcessing and TextFileExamples on elearning.
4. Included file called data.txt contains Player's data. Your project will be graded using a similar input file. Your project must run with an input file formatted as data.txt is formatted. Note the file format is as follows:
1. Number of scores
2. Character designation of type of player (G - golfer, B - bowler)
3. Name data etc
4. Score data
5. Create an Array of Players objects.
1. Populate the Array with both Golfer and Bowler objects.
2. After the Array is filled, call the toString method on each object in the Array. Ensure each iteration calls the correct object.
11. HandicapCalJUnitTest Class
1. Create a JUnit class
2. Create two Player instance variables.
3. Create two test methods
1. testGolferCalculateHandicap()
1. Creates Golfer object and assigns to a Player object variable
2. Test the calculateHandicap method for the Golfer object.
2. testBowlerCalculateHandicap()
1. Creates Bowler object and assigns to Player object variable
2. Test the calculateHandicap method for the Bowler object.
12. Create UML Class Diagram for the final version of your project.
The diagram should include:
1. All instance variables, including type and access specifier (+, -);
2. All methods, including parameter list, return type and access specifier (+, -);
3. Include Generalization and Aggregation where appropriate.
4. The PlayerTester does not need to be included.
5. Refer to the UML Distilled pdf on the content page as a reference for creating class diagrams.
6. A Link to a drawing program, Dia, is also posted on the content page.
Submission Requirements: Your project must be submitted using the instructions below.
Any submissions that do not follow the stated requirements will not be graded.
1. You should have 10 files for this assignment: o
Golfer.java - The Golfer class
Score.java - The Golfer's Score class
Course.java - The score's Course class
Bowler.java - The Bowler class
BowlerScore.java - The Bowler's Score class
Player.java - An abstract super class of players
PlayerTester.java A driver program for your project
HandicapCalJUnitTest.java JUnit class to test calculateHandicapp methods.
data.txt - your test file
Simply UML Class diagram of your 5 classes, do not include the Tester. (Dia file or image file , jpg, gif, pdf etc)
The javadoc files for all the classes except the tester.(Do not turn in)
2. Remember to compile and run your program one last time before you submit it. If your program will not compile, the graders will not be responsible for trying to test it.
3. Follow the submission requirements posted on elearning.
Provided data.txt file to read from
**data.txt**
2 G Hugh Hefner,Rocky Bayou Country Club Bluewater Country Club,75,10/23/2013,70.5,113 Rocky Bayou Country Club,82,01/21/2014,68.5,123 3 B Dan Bilzerian,Ignite Felton Lanes, 112,09/22/2012 Bowlarama, 142,09/24/2012 Cordova Lanes,203,09/24/2012 2 G Tiger Woods,Isleworth Augusta,68,04/08/2013,76.2,135 Bethpage Black,71,06/21/2012,76.6,144 3 B Earl Anthony,Nine Mile Denny's Firestone Lanes, 223,09/22/1968 Bowlarama, 246,09/24/1976 Cordova Lanes,210,09/24/1977
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
