gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:42:39 24 4
gpt4 key购买 nike

强调文本我已经研究这个问题一段时间了,并设法消除了此类上的几乎所有错误。这个错误一直说我缺少方法体或声明抽象,但我只是没有看到它。我已经成功完成了另一门与此几乎相似的类(class),但这一门似乎表现得很奇怪。有人可以帮我吗?如果你愿意的话谢谢你。

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);
}
}

最佳答案

改变

public int setGoal(int newGoal)

public void setGoal(int newGoal)

Setter 方法通常没有返回类型(并且基于您不尝试返回任何内容的事实,您可能不希望它具有 int 返回类型) .

也改变

public void writeOutput();

public void writeOutput()

关于Java 错误 - 缺少方法体或声明抽象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29404339/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com