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

In JAVA, Write 2 classes encapsulating the concept of statistics for a baseball

ID: 657775 • Letter: I

Question

In JAVA, Write 2 classes encapsulating the concept of statistics for a baseball team

A player class that has the attributes player name, at bats, hits, and average. (I Made It already) Need Help With Team Info*

A Team info class which has the following attributes: a team name, totals hits, team average, player array, max player, player count

Needs to include:

- A constructor method

- add player method

- update stats

- get stats

- to string

PLAYER CLASS

/**********************************************************************
*Program Name :   
*Author :   
*Due Date :   
*Course/Section :   
*Program Description: Write a program to create an array based on a
*
*
*Constructor: initializes the instance data
*updateStats: adds hits and at bats to the totals in the instance data
*toString : formats the instance data for display
*********************************************************************/
import java.text.*;

public class BaseballPlayer
{
   //class constants

   //class variables
   private String name; //players first and last name
   private int hits; //players hit total
   private int atBats;   //number of attempts
   private float avg; //players batting average

/**********************************************************************
*Method Name : BaseballPlayer(constructor)
*Author :   
*Due Date :   
*Course/Section :   
*Program Description: This constructor will intialize the instance data
* to values passed in via the parameter list.
*
*BEGIN BaseballPlayer
* initialize all instace data
*END Baseball Player
***********************************************************************/

public BaseballPlayer(String inName, int inHits, int inAtBats)
{
   //local constants

   //local variables

   /******************************************************/

   //initialize the instance data
   name = inName;
   atBats = inBats;
   hits = inHits;
   avg = (float)hits / atBats;

}//end constructor
/**********************************************************************
*Method Name : Update Stats
*Author :   
*Due Date :   
*Course/Section :   
*Program Description: This method will format the instance data in a
* manner fit for display
*
*BEGIN update stats(hits, at bats)
* add hits to total hits in the class data
* add at bats to total at bats in the class data
* recalculate the batting average
*END Baseball Player
***********************************************************************/

public void updateStats(int inAtBats, int inHits)
{
   //local constants


   //local variables

   /*******************************************************************/

//update player at bats
atBats += inAtBats;

//update player hits
hits += inHits;

   //recalculate the batting average
   avg = (float)hits / atBats;

}//end updateStats

/**********************************************************************
*Method Name : toString
*Author :   
*Due Date :   
*Course/Section :   
*Program Description: This method will format the instance data in a
* manner fit for display
*
*BEGIN BaseballPlayer
* IF(player name is too long)
* make it 10 characters long
* ELSE
* padd the name to be 10 characters long
* END IF
* Create output string
* return output string
*
*END Baseball Player
***********************************************************************/

public String toString()
{
   //local constants
   final int NAME_LENGTH = 10;

   //local variables
   String fmtName; //name from instance data formatted to NAME_LENGTH
   String output; //formatted instance data
   DecimalFormat fmt = new DecimalFormat("0.000");
   String avgFmt = fmt.format(avg);

   /*******************************************************************/

//IF(player name is too long)
if (name.length() > NAME_LENGTH)

//make it 10 characters long
fmtName = name.substring(0,10);

//ELSE name is not too long
else

//padd the name to be 10 characters long
fmtName = Util.setRight(NAME_LENGTH, name);

//END IF

//Create output string
output = Util.setLeft(29, "Name : ") + fmtName + " " +
       Util.setLeft(29, "At Bats:: ") + Util.setRight(NAME_LENGTH + 5, "" + hits) + " " +
Util.setLeft(29, "Hits : ") + Util.setRight(NAME_LENGTH + 5, "" + hits) + " " +
Util.setLeft(29, "Avg : ") + Util.setRight(NAME_LENGTH + 5, "" + avgFmt);

//return output string
   return output;

}//end toString

}//end BaseballPlayer class

Explanation / Answer

package edu.home.control; public class ControlClass { //this line compiles fine private TheClass x; //compilation error, it can't access for being in a different package private AnotherClass y; //compilation error, it can't access because its scope works only in TheClass private SomeClass z; }

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