Java错误 - 缺少方法体或声明抽象

时间:2015-04-02 03:04:44

标签: java compiler-errors syntax-error

强调文字我一直在研究这个问题,并设法摆脱这个类几乎所有的错误。这个错误一直说我缺少方法体或声明抽象,但我只是没有看到它。我设法完成了另一个几乎与此相似的课程,但这个课程似乎很奇怪。有人可以帮帮我吗?谢谢你。

import java.util.Scanner;
public class HockeyPlayer extends StudentAthlete
{
  Scanner keyboard = new Scanner(System.in);
  public static void main (String [] args)
  {
    HockeyPlayer athlete1 = new HockeyPlayer("Dave", 111111, 15, 3.2, 2, 3);

    athlete1.writeOutput();
  }

  private int assist = 0;
  private int goal = 0;

  public HockeyPlayer()
  {
    super();
    goal = 0;
    assist = 0;
  }

  public int getAssist()
  {
    return  assist;
  }

  public void setAssist(int newAssist)
  {
    if (0 >= newAssist)
    {
      assist = newAssist;
    }
    else
    {
      System.out.println("Invalid Assists");
      System.out.println("Please enter a valid Assists");
      int tempAssist = keyboard.nextInt();
      setAssist(tempAssist);
    }
  }

  public int getGoal()
  {
    return goal;
  }

  public int setGoal(int newGoal)
  {
    if (0 >= newGoal)
    {
      goal = newGoal;
    }

    else
    {
      System.out.println("Invalid Goals");
      System.out.println("Please enter a valid Goals");
      int tempGoal = keyboard.nextInt();
      setGoal(tempGoal);
    }
  } 

  public HockeyPlayer(String initialName, int initialStudentNumber, int initialJersey, double initialGpa, int initialGoal, int initialAssist)
{
    super (initialName, initialStudentNumber,initialJersey, initialGpa);
    setGoal(initialGoal);
    setAssist(initialAssist);
}

  public HockeyPlayer(String initialName, int initialStudentNumber, int initialJersey, double initialGpa)
  {
    super (initialName, initialStudentNumber, initialJersey, initialGpa);
    goal = 0;
    assist= 0;
  }

  public HockeyPlayer(String initialName, int initialStudentNumber)
  {
    super (initialName, initialStudentNumber);
    goal = 0;
    assist = 0;    
  }

  public HockeyPlayer(String initialName)
  {
    super(initialName);
    goal = 0;
    assist = 0;
  }

  public void writeOutput(); // THE ERROR OCCURS HERE
  {
    super.writeOutput();
    System.out.println("Goals: " + goal);
    system.out.println("Assists: " + assist);
  }
}

1 个答案:

答案 0 :(得分:1)

变化

public int setGoal(int newGoal)

public void setGoal(int newGoal)

Setter方法通常没有返回类型(并且基于您不尝试返回任何内容的事实,您可能不打算使用int返回类型)。

同时更改

public void writeOutput();

public void writeOutput()