Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an abstract SoftballPlayer class that stores softball player data and pro

ID: 3689890 • Letter: C

Question

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.

getNumber: Accepts no parameters and returns a String representing the number.

setNumber: Accepts a String representing the number, sets the field, and returns nothing.

getName: Accepts no parameters and returns a String representing the name

setName: Accepts a String representing the name, sets the field, and returns nothing

getPosition: Accepts no parameters and returns a String representing the position.

setPosition: Accepts a String representing the position, sets the field, and returns nothing.

getBattingAvg: Accepts no parameters and returns a double representing batting average.

setBattingAvg: Accepts a double representing the batting average, sets the field, and returns nothing

getSpecializationFactor: Accepts no parameters and returns a double representing the specialization factor.

setSpecializationFactor: Accepts a double representing the specialization factor, sets the field, and returns nothing.

getCount: Accepts no parameters and returns an int representing the count. Since count is static, this method should be static as well.

resetCount: Accepts no parameters, resets count to zero, and returns nothing. Since count is static, this method should be static as well.

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.

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().

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

public abstract class SoftballPlayer{
   String number;
   String name;
   String position;
   double specializationFactor;
   double battingAvg;
   static int count = 0;
   static final int BASE_RATING = 10;
   public SoftballPlayer(String number, String name, String position, double specializationFactor, double battingAvg) {
       this.number = number;
       this.name = name;
       this.position = position;
       this.specializationFactor = specializationFactor;
       this.battingAvg = battingAvg;
       count++;
   }
   public String getNumber() {
       return number;
   }
   public void setNumber(String number) {
       this.number = number;
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public String getPosition() {
       return position;
   }
   public void setPosition(String position) {
       this.position = position;
   }
   public double getSpecializationFactor() {
       return specializationFactor;
   }
   public void setSpecializationFactor(double specializationFactor) {
       this.specializationFactor = specializationFactor;
   }
   public double getBattingAvg() {
       return battingAvg;
   }
   public void setBattingAvg(double battingAvg) {
       this.battingAvg = battingAvg;
   }
   public static int getCount() {
       return count;
   }
   public static void resetCount() {
       count = 0;
   }
   String stats(){
       return "Batting average: " + battingAvg;
   }
   public String toString(){
       return stats();
   }
   abstract double rating();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote