Java 错误:在我创建的类中读取文本文件时出现问题

Java 错误:在我创建的类中读取文本文件时出现问题,java,class,text,compiler-errors,java-7,Java,Class,Text,Compiler Errors,Java 7,当我运行我的程序(BaseBallStatClient)时,我收到错误:找不到团队名称、max和min的符号 更新: 我现在有一个问题,我认为是文本文件的读取,团队名称的输出值是tars.txt,最大值和最小值在我运行程序时是0.0。我认为在第一段代码中,我没有正确阅读文本文件 Txt文件: Tars 0.592 0.427 0.194 0.445 0.127 0.483 0.352 0.190 0.335 0.207 0.116 0.387 0.243 0.225 0.401 0.382 0

当我运行我的程序(BaseBallStatClient)时,我收到错误:找不到团队名称、max和min的符号

更新:

我现在有一个问题,我认为是文本文件的读取,团队名称的输出值是tars.txt,最大值和最小值在我运行程序时是0.0。我认为在第一段代码中,我没有正确阅读文本文件

Txt文件:

Tars 
0.592
0.427
0.194
0.445
0.127
0.483
0.352
0.190
0.335
0.207
0.116
0.387
0.243
0.225
0.401
0.382
0.556
0.319
0.475
0.279  
这是我创建的类文件,我认为它如何读取文本文件存在问题:

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class BaseballStats {

  private String fileName;
  private String teamName;
  private double [] battingAverage;


  public BaseballStats ( String fileName ) {
    this.fileName = fileName;
    boolean firstLine = true;
    Scanner input = new Scanner(fileName);
    while (input.hasNextLine()) {
      String line = input.nextLine();
      if (firstLine) {
        setTeamName (line);
        firstLine = false;
        continue;
      }
      int i=0;
      while(input.hasNext()) {
        battingAverage[i] = input.nextDouble();
        i++;      
      }
    }
  }

  public String getTeamName( ) {
    return teamName;
  }

  public void setTeamName( String newTeamName ) {
    teamName=newTeamName;
  }

  public double findMaxAverage( ) {
    double max =battingAverage[0];
    for ( int i =1; i < battingAverage.length; i++) {
      if(battingAverage[i] >max)
        max= battingAverage[i];
    }
    return max;
  }
  public double findMinAverage( ) {
    double min =battingAverage[0];
    for ( int i =1; i < battingAverage.length; i++) {
      if(battingAverage[i] < min)
        min= battingAverage[i];
    }
    return min;
  }    
  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.
  }
}
您尚未定义它们并尝试打印它们

使用返回值定义变量

对于剩余的
min
max
变量也是如此

而且你可以直接做

 System.out.println("The " + newTeam.getTeamName() + " statistics are:");

注意
newTeam
,may
null

您尚未定义返回值

您可以这样做:

String returnValue =newTeam.getTeamName( );
System.out.println("The value is " + returnValue);

或者只是
System.out.println(“newTeam.getTeamName()+”统计信息是:”,如果不需要验证(在这种情况下,最好在BaseballStats类中进行验证)。好的,谢谢您解决了错误,但它输出了团队名称tars.txt,这是文件名,最大值和最小值输出为0.0i。我已更新代码,我认为在第一节中读取文本文件有一个问题code@user2985542查看读取文件中的if-else条件。这可能就是问题所在。我在看,但我不知道我应该看什么好的,我已经解决了这个问题,但我认为文本文件的读取方式存在问题,因为最大值和最小值是在0.0输出的,团队名称就是文件名
   String teamName =newTeam.getTeamName( );
   System.out.println("The " + teamName + " statistics are:");
 System.out.println("The " + newTeam.getTeamName() + " statistics are:");
String returnValue =newTeam.getTeamName( );
System.out.println("The value is " + returnValue);