Help Please : I need help making array of player which is entered by the user wi
ID: 656812 • Letter: H
Question
Help Please : I need help making array of player which is entered by the user with the use of the 2 classes
I Need to make 2 classes a baseball playerstats, which i made already but i need help with the team info class the methods for the teaminfo class constructor(String name,int maxPlayers) , addPlayer(BaseballPlayerStats) :boolean, updatestats(int hits,intatBats,int index): boolean, getStats(int index), toString()
/**********************************************************
* Program Name : Creating Classes
* Author :
* Date : April 22, 2015
* Course/Section :
* Program Description:
*
* Methods:
* -------
* Main - manages Class Player
*
**********************************************************/
import java.text.DecimalFormat;
public class Player
{
//class constants
//class variables
private String fullName;
private int hits;
private int atBats;
private float batAvg;
/**********************************************************
* Method Name : Class Player
* Author :
* Date : April 22, 2015
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN Constructor
*
* END Constructor
**********************************************************/
public Player()
{
//local constants
//local variables
String fullName;
int hits;
int atBats;
int batAvg;
/******************** Start main method *****************/
//create a constructor that will receive the name of the player and init all other class data to 0
fullName = "";
hits = 0;
atBats = 0;
batAvg = 0;
}//end constructor
/**********************************************************
* Method Name : Player
* Author :
* Date : April 22, 2015
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN Constructor
*
* END Constructor
**********************************************************/
public Player(String fullName, int hits,int atBats)
{
//local constants
//local variables
/******************** Start main method *****************/
//create a constructor that will receive the name of the player and init all other class data to 0
this.fullName = fullName;
this.hits = hits;
this.atBats = atBats;
batAvg = 0;
}//end constructor
/**********************************************************
* Method Name : setHits
* Author :
* Date : April 22, 2015
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN updateGrades
*
* END updateGreades
**********************************************************/
public void setHits(int hits)
{
//local constants
//local variables
/******************** Start main method *****************/
//method that set hits
this.hits=hits;
}//end setHits
/**********************************************************
* Method Name : setHits
* Author :
* Date : April 22, 2015
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN updateGrades
*
* END updateGreades
**********************************************************/
public void setBats(int bats)
{
//local constants
//local variables
/******************** Start main method *****************/
//method that set hits
this.atBats=bats;
}//end setBats
/**********************************************************
* Method Name : addToTotal
* Author :
* Date : April 22, 2015
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN updateGrades
*
* END updateGreades
**********************************************************/
public void addToTotal(int hits, int atBats)
{
//local constants
//local variables
/******************** Start main method *****************/
//Add hits to the class hits variable
this.hits = this.hits + hits;
//Add hits to the class hits variable
this.atBats=this.atBats+atBats;
}//end update
/**********************************************************
* Method Name : updateAverage
* Author :
* Date : April 22, 2015
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN toString
*
* END Creating Methods
**********************************************************/
public void updateAverage()
{
//local constants
//local variables
/******************************************************/
//create a method that will calculate a players batting average using the current instance data
batAvg = (float)hits / (float)atBats;
}//end toString
/**********************************************************
* Method Name : toString
* Author :
* Date : April 22, 2015
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN toString
*
* END Creating Methods
**********************************************************/
public String toString()
{
//local constants
final int NAME_LENGTH = 15;
//local variables
String playerStringDescription;
/******************************************************/
//The name should be exactly 15 characters long.
//The average should be displayed to 3 decimal places.
DecimalFormat formatter=new DecimalFormat("##.000");
//Call update method
updateAverage();
//display info
System.out.print(" " + Util.setLeft(33,"Display Info" + " "));
//The name should be exactly 15 characters long.
if(fullName.length() > NAME_LENGTH)
{
fullName = fullName.substring(0, 15);
}
//create a toString method that will format the instance data on 1 line.
playerStringDescription = Util.setLeft(15, "Name: "+fullName+ " Hits: = "+hits+ " Bats: = "+atBats+ " BatAvg: = "+ Util.setRight(6,"" +formatter.format(batAvg)) + " ");
return playerStringDescription;
}//end toString
} //end Creating Classes
-------------------------------------
/**********************************************************************
*Program Name :
*Author :
*Due Date :
*Course/Section : CSC 111 - 001
*Program Description: Write a program to create an array based on a
*
*
*Constructor:
*addPlayer :
*updateStats:
*getStats :
*toString :
*********************************************************************/
public class TeamInfo
{
//class constants
//class variables
private String teamName; //players first and last name
private int totalHits; //players hit total
private int totalAtBats; //number of attempts
private float teamAvg; //players batting average
private int playerCount;
private int maxPlayers;
Player[] = BaseballPlayerStats;
Explanation / Answer
* Program Name : Creating Classes
* Author :
* Date : April 22, 2015
* Course/Section :
* Program Description:
*
* Methods:
* -------
* Main - manages Class Player
*
**********************************************************/
import java.text.DecimalFormat;
public class Player
{
//class constants
//class variables
private String fullName;
private int hits;
private int atBats;
private float batAvg;
/**********************************************************
* Method Name : Class Player
* Author :
* Date : April 22, 2015
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN Constructor
*
* END Constructor
**********************************************************/
public Player()
{
//local constants
//local variables
String fullName;
int hits;
int atBats;
int batAvg;
/******************** Start main method *****************/
//create a constructor that will receive the name of the player and init all other class data to 0
fullName = "";
hits = 0;
atBats = 0;
batAvg = 0;
}//end constructor
/**********************************************************
* Method Name : Player
* Author :
* Date : April 22, 2015
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN Constructor
*
* END Constructor
**********************************************************/
public Player(String fullName, int hits,int atBats)
{
//local constants
//local variables
/******************** Start main method *****************/
//create a constructor that will receive the name of the player and init all other class data to 0
this.fullName = fullName;
this.hits = hits;
this.atBats = atBats;
batAvg = 0;
}//end constructor
/**********************************************************
* Method Name : setHits
* Author :
* Date : April 22, 2015
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN updateGrades
*
* END updateGreades
**********************************************************/
public void setHits(int hits)
{
//local constants
//local variables
/******************** Start main method *****************/
//method that set hits
this.hits=hits;
}//end setHits
/**********************************************************
* Method Name : setHits
* Author :
* Date : April 22, 2015
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN updateGrades
*
* END updateGreades
**********************************************************/
public void setBats(int bats)
{
//local constants
//local variables
/******************** Start main method *****************/
//method that set hits
this.atBats=bats;
}//end setBats
/**********************************************************
* Method Name : addToTotal
* Author :
* Date : April 22, 2015
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN updateGrades
*
* END updateGreades
**********************************************************/
public void addToTotal(int hits, int atBats)
{
//local constants
//local variables
/******************** Start main method *****************/
//Add hits to the class hits variable
this.hits = this.hits + hits;
//Add hits to the class hits variable
this.atBats=this.atBats+atBats;
}//end update
/**********************************************************
* Method Name : updateAverage
* Author :
* Date : April 22, 2015
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN toString
*
* END Creating Methods
**********************************************************/
public void updateAverage()
{
//local constants
//local variables
/******************************************************/
//create a method that will calculate a players batting average using the current instance data
batAvg = (float)hits / (float)atBats;
}//end toString
/**********************************************************
* Method Name : toString
* Author :
* Date : April 22, 2015
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN toString
*
* END Creating Methods
**********************************************************/
public String toString()
{
//local constants
final int NAME_LENGTH = 15;
//local variables
String playerStringDescription;
/******************************************************/
//The name should be exactly 15 characters long.
//The average should be displayed to 3 decimal places.
DecimalFormat formatter=new DecimalFormat("##.000");
//Call update method
updateAverage();
//display info
System.out.print(" " + Util.setLeft(33,"Display Info" + " "));
//The name should be exactly 15 characters long.
if(fullName.length() > NAME_LENGTH)
{
fullName = fullName.substring(0, 15);
}
//create a toString method that will format the instance data on 1 line.
playerStringDescription = Util.setLeft(15, "Name: "+fullName+ " Hits: = "+hits+ " Bats: = "+atBats+ " BatAvg: = "+ Util.setRight(6,"" +formatter.format(batAvg)) + " ");
return playerStringDescription;
}//end toString
} //end Creating Classes
-------------------------------------
/**********************************************************************
*Program Name :
*Author :
*Due Date :
*Course/Section : CSC 111 - 001
*Program Description: Write a program to create an array based on a
*
*
*Constructor:
*addPlayer :
*updateStats:
*getStats :
*toString :
*********************************************************************/
public class TeamInfo
{
//class constants
//class variables
private String teamName; //players first and last name
private int totalHits; //players hit total
private int totalAtBats; //number of attempts
private float teamAvg; //players batting average
private int playerCount;
private int maxPlayers;
Player[] = BaseballPlayerStats;
TeamInfo(String name, int mPlayers)
{
teamName = name;
maxPlayers=mPlayers;
}
};
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.