我很难理解我的项目说明,英语是我的第二语言,所以有人可以帮助分解它并协助我如何进行这个项目吗?
项目摘要
编写一个为棒球队制作统计数据的程序。
说明:
创建BaseballStats类:
它有两个实例变量:
teamName,一个字符串
battingAverages,一组双打,代表球队中所有球员的击球平均值。
该类具有以下API:
构造函数:
public BaseballStats( String filename )
团队名称和团队的击球平均值存储在文件中。您可以假设文件中的第一项是团队名称(一个单词 - 没有空格),接着是正好20个击球平均值。您的构造函数应将该文件读入teamName实例变量和battingAverages数组。
方法:
public String getTeamName( )
accessor for teamName
public void setTeamName( String newTeamName )
mutator for teamName
public double maxAverage( )
returns the highest batting average
public double minAverage( )
returns the lowest batting average
public double spread( )
returns the difference between the highest and lowest batting averages
public int goodPlayers( )
returns the number of players with an average higher than .300
public String toString( )
returns a String containing the team name followed by all the batting averages formatted to three decimal places.
客户类:
您的客户端应该实例化BaseballStats类的对象,传递包含团队名称和平均值的文本文件的名称。然后,客户端应调用所有方法,将结果报告为输出。
答案 0 :(得分:1)
在您评论之前,您似乎从未使用过Java。以下是它应该如何布局:
class BaseballStats {
private String filename;
public BaseballStats ( String filename )
{
this.filename = filename;
}
public String getTeamName( )
{
//accessor for teamName
}
public void setTeamName( String newTeamName )
{
//mutator for teamName
}
public double maxAverage( )
{
//returns the highest batting average
}
public double minAverage( )
{
//returns the lowest batting average
}
public double spread( )
{
//returns the difference between the highest and lowest batting averages
}
public int goodPlayers( )
{
//returns the number of players with an average higher than .300
}
public String toString( )
{
//returns a String containing the team name followed by all the batting averages formatted to three decimal places.
}
}
您的客户端(同一目录中的另一个java文件)可以使用以下命令创建此类的实例:
BaseballStats newTeam = new BaseballStats(filename);