Help Please : I need help making array of player which is entered by the user wi
ID: 656690 • 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
import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.PrintStream;
import java.io.*;
import java.text.*;
public class player {
player[] players = new player[5];
public static void main(String[] args)
{
public void setPlayers(int n, player newPlayers)
{
players = newPlayers;
}
player baseball = new Baseballplayer();
Scanner input = new Scanner(System.in);
for (int i=0; i < 6; i++)
{
baseball = new Baseballplayer();
System.out.printf(" enter baseball players name: " );
String a = input.nextLine();
baseball.SetName(a);
System.out.printf("enter baseball team: " );
String b = input.nextLine();
baseball.SetTeamName(b);
System.out.printf(" enter baseball games played: " );
int c = input.nextInt();
baseball.SetPlayed(c);
System.out.printf("enter baseball players A: " );
int d = input.nextInt();
((Baseballplayer)baseball).SetA(d);
System.out.printf(" enter baseball hits: " );
int e = input.nextInt();
((Baseballplayer)baseball).SetH(f);
System.out.printf(" enter baseball players H: " );
int f = input.nextInt();
((Baseballplayer)baseball).SetH(f);
Baseballplayer.ShowStats();
setPlayers(i,baseball);
}
----------------------------------
public abstract class player implements IName, ISerializable {
protected String name;
protected String TeamName;
protected int GamesPlayed;
public player()
{
name = "n";
TeamName = "T";
GamesPlayed = 0;
}
public String GetName()
{
return n;
}
public void SetName(String NewName)
{
NewName = n;
}
public String GetT()
{
return T;
}
public void SetT(String newT)
{
newT = T;
}
public int GetPlayed(){
return GamesPlayed;
}
public void SetPlayed(int played)
{
played = GamesPlayed;
}
abstract void ShowStats();
public void Save(PrintStream p);
}
---------------------
public class Baseplayer extends p
{
private int A, h, H;
public Baseballplayer()
{
A = 0;
h =0;
H = 0;
}
public int GetAB(){
return A;
}
public void SetA(int newA){
newAB = A;
}
public int GetHits(){
return hits;
}
public void SetHits(int newHits){
newHits = hits;
}
public int GetH(){
return H;
}
public void SetHR(int newH){
newHR = H;
}
public double Avg(){
double avgBat;
avgBat = hits/A;
return avgBat;
}
public void ShowStats(){
double avg = Avg();
System.out.printf("%s %s %d %d %d %f %d", n, T, GamesPlayed, A, h, avg, H);
}
public void Save(PrintStream p){
double avg = Avg();
ps.printf("%s %s %d %d %d %f %d", n, T, GamesPlayed, A, h, avg, H);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.