Using This Class I need to make a program I have to make a program using the cla
ID: 653878 • Letter: U
Question
Using This Class I need to make a program
I have to make a program using the class below :creating a menu one for 1.creating a player, 2.edit stats, 3.display, and 4.quit
When i type 1 it should make me create a player -type in player first and last name, at bats , hits. When i type 2 it should let do the same thing. When i type 3 it should display the at bats, hits and average. When i type 4 it should quit the program
/**********************************************************
* Program Name : Practice Coding - Creating Classes
* Author :
* Date : April 01, 2010
* Course/Section : CSC111 - 01
* Program Description:
*
* Methods:
* -------
* Main - manages Class Player
*
**********************************************************/
public class Class Player
{
//class constants
//class variables
private String name;
private int hits;
private int atBats;
private float batAvg;
/**********************************************************
* Method Name : Constructor
* Author :
* Date : April 01, 2010
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN Constructor
*
* END Constructor
**********************************************************/
public Player(String inName)
{
//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
name = inName;
hits = 0;
atBats = 0;
badAvg = 0;
}//end constructor
/**********************************************************
* Method Name : updateGrades
* Author :
* Date : April 01, 2010
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN updateGrades
*
* END updateGreades
**********************************************************/
public void addToTotal(int hits, int atBats)
{
//local constants
//local variables
int start_Hits;
int start_AtBats;
/******************** Start main method *****************/
//create a method that will receive hits and at bats for a player and add them to his total
start_Hits = start_Hits + hits;
start_AtBats = start_AtBats + atBats;
}//end update
/**********************************************************
* Method Name : updateAverage
* Author :
* Date : April 01, 2010
* 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
start_BatAvg = (float)start_Hits / (float)start_AtBats;
}//end toString
/**********************************************************
* Method Name : toString
* Author :
* Date : April 01, 2010
* Course/Section : CSC111 - 01
* Program Description:
*
* BEGIN toString
*
* END Creating Methods
**********************************************************/
public String toString()
{
//local constants
//local variables
/******************************************************/
//create a method that will calculate a players batting average using the current instance data
System.out.println(name =" + name + ", hits =" + hits +", atBats =" + atBats + ", batAvg =" + batAvg + ");
}//end toString
} //end Creating Classes
Explanation / Answer
public class Player
{
private String name;
private int hits;
private int atBats;
private float Avg;
public Player(String inName)
{ this.name = inName;
this.hits = 0;
this.atBats = 0;
this.Avg = 0;
}
public void addToTotal(int Hits, int AtBats)
{
int start_Hits=Hits;
int start_AtBats=AtBats;
this.hits = this.hits+start_Hits ;
this.atBats = start_AtBats +this. atBats;
}
public void updateAverage()
{ this.Avg=this.hits/this.atBats;
}
public String toString()
{
return String.format(
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.