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 ArrayList of object references. 5. Use method calls to perform logic steps involved in calculations. 6. Implement a solution involving polymorphism. Prep Readings: Java zyBooks Chapters 1 - 10. 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. In this project will be extending the Score and Golfer class we developed in Project 2 and adding classes required to calculate a Bowlers handicap. Below are the steps we will use to calculate handicaps in both games. 2. Your code should ensure all instance field are valid as described in their requirements. If not create a user defined exception called FieldOutOfBounds that 1. Display an error message to the standard output stating that the field must be set between specific values and continue. 2. Set the field value to 9999. 3. For example, the bowling score must be between 0 and 300(inclusive) so the exception would be throw and the message would state: The bowlers score must be between 0 and 300(inclusive) 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. (Assume scores are entered from oldest to newest) 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 subtracted 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. (Assume scores are entered from oldest to newest) 1. Stroke differential is calculated using the following formula: 2. Differential = (Score - course Rating) x (113 / Slope) : 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% o f 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 Classes from Project 2 (Golfer and Score) will be reused with the following modifications: 1. Golfer Class - Must extend the Player abstract class (listed below) 1. Change from Array of Score objects to ArrayList of Score Objects. 2. Add a calculateHandicap method that returns a double representing the golfers current handicap. (Player's class abstract method) 3. Modify methods as required to accommodate the changes in the Score class. 4. Note: that Name and IDnum are stored in the Player class. 5. The toString methods return should be format similar to Project 2. However, add the current handicap to the output. See Bowler class for an example. 2. Score Class 1. Modify the course instance variable from a String to a Course object (see below) that contains the course name, course rating and course slope. 2. Remove the course rating and course slope instance fields. 3. Modify the rest of the methods and constructor to accommodate the change in the storage of course information. 4. Score is a gross score thus without any handicap added or subtracted. 5. The toString methods return should be format similar to Project 2. 6. 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 7. The Bowler Class - Must extend the Player class listed below 1. Instance Variables 1. teamName - A String representing the bowler's team. 2. ArrayList of BowlerScore objects - stores all the bowler's scores. 2. Methods 1. Constructor - sets name and teamName from parameters and uses the static variable nextIDNum to retrieve the next available ID number. Creates ArrayList. 2. Constructor - default constructor, sets all instance field to a default value. Creates ArrayList. 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 ArrayList 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 7. 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 ? 8. The Player 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 and all their scores. 5. calculateHandicap - abstract method that returns a double representing the players handicap 9. 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. 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 processing is covered in additional Slide and example in the TextFileProcess.zip on our course web site. 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 ArrayList of Players objects. 1. Populate the ArrayList with both Golfer and Bowler objects. 2. After the ArrayList is filled, call the toString method on each object in the ArrayList. Ensure each iteration calls the correct object. 10. Create UML Class Diagram for the final version of your project. Follow the guidelines as outlined in Project 2. 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 o Score.java - The Golfer's Score class o Course.java - The score's Course class o Bowler.java - The Bowler class o BowlerScore.java - The Bowler's Score class o Player.java - An abstract super class of players o PlayerTester.java - A driver program for your project o FieldOutOfBounds.java User defined exception class o data.txt - your test file o Simply UML Class diagram of your 6 classes, do not include the Tester. (Dia file or image file, jpg, gif, pdf etc.)

How To create FieldOutOfBounds.java class file..I have created below can someone correct my errors

import java.util.*;

import java.text.*;

class FieldOutOfBoundException extends Exception {

FieldOutOfBoundException(inCourseRating) {

}

super(inCourseRating);

}

------------------------------------------------------------------------------

Course.java (I have to remove print error() )

/**

The Course class represents all item required to accurately depict a golf course

File Name: Score.java

*/

public class Course

{

//Instance Variables

//courseName - a String representing the name of the course.

private String courseName;

//CourseRating - a double representing the course rating, it must be between 60 and 80. (inclusive)

private double courseRating;

//courseSlope - an int representing the course slope, it must be between 55 and 155 (inclusive).

private int courseSlope;

private static final int MIN_COURSE_RATING = 60;

private static final int MAX_COURSE_RATING = 80;

private static final int MIN_COURSE_SLOPE = 55;

private static final int MAX_COURSE_SLOPE = 155;

//Methods

//Constructor - sets all instance fields from parameters

//Default Constructor - sets all instance fields to a default value. Chained...

public Course() throws Exception

{

this("Bay Hill CC", 69.5, 123);

}

public Course(String inCourseName, double inCourseRating, int inCourseSlope) throws Exception

{

setCourseName(inCourseName);

setCourseRating(inCourseRating);

setCourseSlope(inCourseSlope);

}

//Access and mutator methods for all instance variables. Mutator method should be used to set all instance fields

public String getCourseName()

{

return courseName;

}//end getCost

public double getCourseRating()

{

return courseRating;

}//end getCourseRating

public int getCourseSlope()

{

return courseSlope;

}//end getCourseSlope

public void setCourseName(String inCourseName)

{

this.courseName = inCourseName;

}//end setCourseName

/**

This constructor sets the Course Rating

to the value passed as an argument.

@param inCourseRating the starting Course Rating.

* @throws Exception

*/

public void setCourseRating(double inCourseRating) throws FieldOutOfBoundsException

{

if ( MIN_COURSE_RATING <= inCourseRating && inCourseRating <= MAX_COURSE_RATING )

{

this.courseRating = inCourseRating;

}

else

{

throw new FieldOutOfBoundsException();

// this.courseRating = 9999;

// printError("Course Rating");

}

}//end setCourseRating

public void setCourseSlope(int inCourseSlope)

{

//slope ratings range from a minimum of 55 (very easy) to a maximum of 155 (extremely difficult)

if ( MIN_COURSE_SLOPE <= inCourseSlope && inCourseSlope <= MAX_COURSE_SLOPE )

{

this.courseSlope = inCourseSlope;

}

else

{

printError("Course Slope");

this.courseSlope = 9999;

}

}//end setCourseSlope

//toString - returns a nicely formated String that contains its instance fields such as:

public String toString()

{

String returnString = "";

returnString = getCourseRating() + "\t\t\t" + getCourseSlope() +"\t\t\t" + getCourseName() + " ";

return returnString;

}

//printError

public void printError(String fieldName)

{

System.out.println("Invalid "+fieldName+"! Field set to 9999.");

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!