Question
1. Create a driver program (Driver.java) that prompts the user for three player stats: For each player, ask the user to input a last name,
1. Create a driver program (Driver.java) that prompts the user for three player stats:
For each player, ask the user to input a last name, # of at bats, and # of hits.
Use Player.java to set the data fields and calculate the batting average
Output player stats in reverse order that they were input.
If the User inputs a last name twice, re-prompt them for another name.
Example input and output
Enter Name, At Bats, Hits -> Ruth 8399 2873
Enter Name, At Bats, Hits -> Griffey 9801 2781
Enter Name, At Bats, Hits -> Rose 14053 4256
LName AtBats Hits Aver
Rose 14053 4256 302.0
Griffey 9801 2781 342.0
Ruth 8399 2873 342.0
Include a method for all output:
public static void outputPlayer( boolean showHeader, Player P ) {
If showHeader is true output the following line and then the Player stats. Otherwise just output the player stats:
FName LName AtBats Hits Aver
2. Create a second class called Pitchers that inherits the methods and data fields of the Players class.
Add:
A double field called innings
An integer field called runs
A double field call ERA
Create the following constructor method:
Pitcher( String LName ) {
Create the appropriate setter and getter methods for the data fields. For the setERA() method, set ERA to be
ERA = innings / runs * 10;
Use the Pitchers class setters and getters method to create the following output
Create a driver program called drivePlayer.java that utilizes the 2 classes to create the following output (properly lined up)
LName At Bats Hits Average Innings Runs ERA
Kofox 776 75 96.0 2324.1 803 3.46
Ruth 8399 2873 342.0 1221.1 309 2.53
Again, use a general method for output:
public static void outputPitcher( boolean ShowHeader, Pitcher P ) {
3. Add one additional polymorphic method called outputGeneralPlayer that could be called with either Pitcher or Player object. Use that method to create the following output:
LName AtBats Hits Aver
Griffey 9801 2781 283.0
Ruth 8399 2873 342.0
Kofax 776 75 96.0
I am stuck on this question and creating the driver program. Can I have any assistance?
public class Player { protected String LName; protected int AtBats; protected int Hits; protected double Aver; Player(){ LName="Ruth"; AtBats=8399; Hits=2873; } Player( String LName){ this.LName = LName; } public void setAverage() { this.Aver = 1000 * this.Hits / this.AtBats; } public double getAverage() { return Aver; } public String getLName() { return LName; } public void setLName(String lName) { LName = lName; } public int getAtBats() { return AtBats; } public void setAtBats(int atBats) { AtBats = atBats; } public int getHits() { return Hits; } public void setHits(int hits) { Hits = hits; } }
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