Question
The following code shows SportsInfo which is an abstract class that holds player statistics for sports. Write two classes that inherit from SprotsInfo. Each will
The following code shows SportsInfo which is an abstract class that holds player statistics for sports. Write two classes that inherit from SprotsInfo. Each will return a different type of Stats object depending on the sport.
public abstract class SportsInfo{
private String playerName;
Public SportsInfo (String name){
player Name= name;
}
public String getName() {return playerName;}
public abstract double getAverage();
}
Write two classes that inherit from SportInfo, one to handle bowling information (BowlingSportsInfo) and one to handle Baseball info (BaseballSportsInfo). They should make use of the superclass constructor, if possible. Only create members specifically needed by that type of SportsInfo.
The constructor for BowlingSportsInfo should have this signature:
Public BowlingSportsInfo(String name, int firstGameScore);
The constructor for BaseballSportsInfo should have this signature:
Public BaseballSportsInfo(String name, Boolean firstAtBatResult);
BowlingSportsInfo tracks scores for bowling games. It should have a member holding an array of integer game scores and a member that is an integer holding number of games. The array of game scores can be declared to hold 100 games. The getAverage() method should return the average score of all games on record. BowlingSportsInfo adds 1 method:
public void addGame(Int score);
BaseballSportsInfo should hold two integer members, the number of at bats (atBats) and the number of hits.
BaseballSportsInfos getAverage() returns the players batting average. The average is hits/atBats.
BaseballSportsInfo must implements 1 additional method:
public void addAtBat(Boolean hit);
The parameter hit indicates if the at bat was a hit.
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