Specifications Overview: This project is the first of three that will involve th
ID: 3689892 • Letter: S
Question
Specifications
Overview: This project is the first of three that will involve the rating and reporting for softball
players. You will develop Java classes that represent categories of softball players including
outfielders, infielders, pitchers and relief pitchers. You may also want to develop an optional driver
class with a main method. As you develop each class, you should create the associated JUnit test file
with the required test methods to ensure the classes and methods meet the specifications. You should
create a jGRASP project upfront and then add the source and test files as they are created. All of your
files should be in a single folder. Below is the UML class diagram for the required classes which
shows the inheritance relationships. The “other” dependency (red dashed line) is for ReliefPitcher
using the constant BASE_RATING in SoftballPlayer. This is not shown for the other subclasses
because they already have a dependency arrow drawn directly to SoftballPlayer.
• SoftballPlayer.java
Requirements: Create an abstract SoftballPlayer class that stores softball player data and
provides methods to access the data.
Design: The SoftballPlayer class has fields, a constructor, and methods as outlined below.
(1) Fields: instance variables for the player’s number of type String, the player’s name of type
String, the player’s position of type String, the player’s specialization factor of type double,
and the player’s batting average of type double; static (or class) variable for the count of
SoftballPlayer objects that have been created (set to zero when declared and incremented in
the constructor); a constant (static final) BASE_RATING of type int with value 10. These
variables should be declared with the protected access modifier so that they are accessible in
the subclasses of SoftballPlayer. These are the only fields that this class should have.
(2) Constructor: The SoftballPlayer class must contain a constructor that accepts five
parameters representing the values to be assigned to the instance fields: number, name,
position, specialization factor, and batting average. Since this class is abstract, the
constructor will be called from the subclasses of SoftballPlayer using super and the parameter
list. The count field should be incremented in the constructor.
(3) Methods: Usually a class provides methods to access (or read) and modify each of its
instance variables (known as get and set methods) along with any other required methods. At
minimum you will need the following methods.
o getNumber: Accepts no parameters and returns a String representing the number.
o setNumber: Accepts a String representing the number, sets the field, and returns
nothing.
o getName: Accepts no parameters and returns a String representing the name.
o setName: Accepts a String representing the name, sets the field, and returns nothing.
o getPosition: Accepts no parameters and returns a String representing the position.
o setPosition: Accepts a String representing the position, sets the field, and returns
nothing.
o getBattingAvg: Accepts no parameters and returns a double representing batting
average.
o setBattingAvg: Accepts a double representing the batting average, sets the field,
and returns nothing.
o getSpecializationFactor: Accepts no parameters and returns a double
representing the specialization factor.
o setSpecializationFactor: Accepts a double representing the specialization
factor, sets the field, and returns nothing.
o getCount: Accepts no parameters and returns an int representing the count. Since
count is static, this method should be static as well.
o resetCount: Accepts no parameters, resets count to zero, and returns nothing. Since
count is static, this method should be static as well.
o stats: accepts no parameters and returns a String representing the batting average.
This should be called in the toString method below to get the batting average. See the
Outfielder class below for an example of batting average in the toString result.
Subclasses Pitcher and ReliefPitcher should override this method so that pitching
statistics are returned instead of batting average.
o toString: Returns a String describing the SoftballPlayer object. This method will be
inherited by the subclasses. This is the only toString method in this project; it should not
be overridden. This methed will call the stats method described above. For an example
of the toString result, see the Outfielder class below. Note that you can get the class
name for an instance c by calling c.getClass().
o rating: An abstract method that accepts no parameters and returns a double
representing the rating of a softball player. Since this is abstract, each non-abstract
subclass must implement this method.
Code and Test: Since the SoftballPlayer class is abstract you cannot create instances of
SoftballPlayer upon which to call the methods. However, these methods will be inherited by the
subclasses of SoftballPlayer. You should consider first writing skeleton code for the methods in order
to compile SoftballPlayer so that you can create the first subclass described below. At this point you
can begin completing the methods in SoftballPlayer and writing the JUnit test methods for your
subclass that tests the methods in SoftballPlayer.
Explanation / Answer
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package softballplayer;
/**
*
* @author Admin
*/
public class SoftballPlayer {
static int count;
protected String playersNumber;
protected String playersName, position ;
protected double specializationFactor, battingAvg;
static final int BASE_RATING = 10;
SoftballPlayer() {
count++;
}
SoftballPlayer(String num, String nm, String pos, double splFctr, double batAvg) {
this.playersNumber = num;
this.playersName = nm;
this.position = pos;
this.specializationFactor = splFctr;
this.battingAvg = batAvg;
} // end param constrctor soft ball player
String getNumber() {
return this.playersNumber; //
}
void setNumber(String num) {
this.playersNumber = num;
}
String getName() {
return this.playersName;
}
void setName(String nm) {
this.playersName = nm;
}
String getPosition() {
return this.position;
}
void setPosition(String pos) {
this.position = pos;
}
double getBattingAvg() {
return this.battingAvg;
}
void setBattingAvg(double batAvg) {
this.battingAvg = batAvg;
}
double getSpecializationFactor() {
return this.specializationFactor;
}
void setSpecializationFactor(double splFactr) {
this.specializationFactor = splFactr;
}
static int getCount() {
return count;
}
static void resetCount() {
count = 0;
}
double stats() {
return this.battingAvg;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.