Question
STEP 1 Create Superclass and Subclasses Create an Eclipse project named JohnDoeHw7, and use the default package, i.e., no package name should be provided. Then
STEP 1 Create Superclass and Subclasses
Create an Eclipse project named JohnDoeHw7, and use the default package, i.e., no package name should be provided. Then inside this project, create the parent class (superclass) Player as specified in the table below. Save it in a file Player.java.
Also create the three child classes (subclasses) shown below. Save each class in a separate file BaseballPlayer.java, FootballPlayer.java, and BasketballPlayer.java
this template file includes the appropriate program header and comments in the class body.
Class names | |||
Player (superclass) | BaseballPlayer (subclass of Player) | FootballPlayer (subclass of Player) | BasketballPlayer (subclass of Player) |
private data | |||
id | number of hits | number of yards | number of shots made |
player name | number of times at bat | number of rushes | number of shots attempted |
team name |
|
|
|
position |
|
|
|
salary |
|
|
|
commission rate |
|
|
|
public methods | |||
constructors | constructors | constructors | constructors |
getters | getters | getters | getters |
setters | setters | setters | setters |
calculate comission | calculate statistics | calculate statistics | calculate statistics |
determine status | determine status | determine status |
Detail specifications:
In class Player:
id is of int type; player name, team name, position is of String type; salary, commission rate is of double type.
There should be two constructors, one is the default constructor with no parameter, and the other has all six parameters to initialize the six private data fields, respectively.
There should be a public getter and setter for each of the six private data fields.
There is one effector method to calculate the commission by multiplying the salary with the commission rate. This method return a double type.
In class BaseballPlayer:
The two private data fields are int type.
There should be two constructors, one is the default constructor with no parameter, and the other has all eight parameters to initialize the six inherited data fields plus the two private data fields, respectively.
There should be a public getter and setter for each of the two private data fields.
There are two effector methods:
calculate statistics : calculate the players batting average by dividing the number of hits by the number of times at bats, it should return a double type
determine status : boolean return type. If the batting average is more than 0.25, return true; o/w return false
In class FootballPlayer:
The two private data fields are int type.
There should be two constructors, one is the default constructor with no parameter, and the other has all eight parameters to initialize the six inherited data fields plus the two private data fields, respectively.
There should be a public getter and setter for each of the two private data fields.
There are two effector methods:
calculate statistics : Calculate the players rushing average by dividing the number of yards by the number of rushes , it should return a double type
determine status : boolean return type. If the rushing average is more than 3.5, return true; o/w return false
In class BasketballPlayer:
The two private data fields are int type.
There should be two constructors, one is the default constructor with no parameter, and the other has all eight parameters to initialize the six inherited data fields plus the two private data fields, respectively.
There should be a public getter and setter for each of the two private data fields.
There are two effector methods:
calculate statistics : Calculate the players shot percentage by dividing the number of shots made by the number of shots attempted , it should return a double type
determine status : boolean return type. If the shot percentage is more than 0.32, return true; o/w return false
The three constant values mentioned in the determine status method as thresholds should be defined as public static final variable in the three subclasses, respectively.
In the same Eclipse project, create a new class file named JohnDoeHw7.java.
This application file has the main method, and inside the main method, it will create two instances of BaseballPlayer, two instances of FootballPlayer, and two instances of BasketballPlayer.
For each instance, you should use the constructor with 8 parameters, and then plug in all 8 parameters directly in the constructor. You can refer to source code TestFruit.java in file inheritanceExample.zip, and see how object myOrange is constructed.
You can use arbitrary values for the 8 parameters in each instance, as long as they are reasonable, for example, in basketball player, number of shots made should be less than number of shots attempted.
Then for each player instance, you need to output the six inherited data fields from Player class, and its commissions, then output the two private date fields, and then the statistics of this player, and the keeping status of this player: true of false. An example output for a football player is as below:
player id: 20
name: Barry Sanders
team: OSU
position: running back
salary: 1000000.00
commission rate: 0.02
commission: 20000.00
number of yards: 2850
number of rushes: 373
statistics: 7.6
keeping status: true
The output precision requirement: for monetary items, two digits after the decimal point; for statistics, one digit after the decimal point.
Generate a simialr output as above for all six players. When you plus in arbitrary parameters to initialize six playes, you can carefully design the parameters so that in each sport category, one player has keeping status as true, and the other player has it as false.
NOTE ADDITIONAL SPECIFICATIONS!!
You do NOT need to use any array in this homework.
The names of the classes must be exactly as stated in the table in page 1 of this document.
You can not CHANGE, ADD or DELETE any instance variable or method to the Player class and its subclasses. However, inside each method, you have the freedom to use and name any local variable that you need. Also in the main method of the application class, you have the freedom to name and use any local variable.
For class Player and its subclasses, you must provide a constructor without arguments and a constructor with a full list of arguments to initialize all inherited data fields (if applicable), and all private data fields.
In main method, you must use constructors with actual parameters to create the required six objects, by hardcoding the arguments in the contructors. NO USER INPUT is needed in this homework!
For the determine statistics method in each subclass, the division should happen between two int type variables, and the result should be double. How do you achieve that? Hint: in the division statement, type converting the dividend from int to double will yiled a double result, such as (double) dividend / divisor
Except for the three threshold values in the three subclasses, all class data must be private, and you must provide public getters and setters for each private instance data.
The methods to calculate statistics must have the exactly SAME name in all classes.
The methods to determine the players status must have exactly the SAME name in all classes and must all return a boolean.
You do NOT need to use any abstract class or abstract method in this homework.
Put each class in a separate file Player.java, BasketballPlayer.java, FootballPlayer.java,.java, BaseballPlayer.java, and JohnDoeHw7.java(for application program that has the main method).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started