当我编译我的代码时,我得到了这个错误:
“PaintballPlayerTest.java:19:错误:PaintballPlayer 类中的方法 recordShot 不能应用于给定类型;sheldon.recordShot(0);需要 ^:未找到参数:int 原因:实际参数列表和正式参数列表的长度不同”
这非常令人沮丧,我希望这里有人可以帮助我。代码如下......
矿:
import java.util.*;
public class PaintballPlayer
{
private String firstName, middleName, lastName;
private String secFirst, secLast;
private int id;
private int count;
private static int totalPlayers;
private int playerID;
private int players;
private int shots;
private static int shotsFired;
public PaintballPlayer(String first, String middle, String last)
{
count = 0;
id = totalPlayers++;
players = count++;
shots = count++;
firstName = first;
middleName = middle;
lastName = last;
}
public PaintballPlayer(String f, String l)
{
this (f,"",l);
id = count++;
}
public PaintballPlayer()
{
totalPlayers++;
}
public static int getTotalPlayers()
{
return totalPlayers;
}
public int recordShot()
{
return count;
}
public String toString()
{
String name;
String n;
name = firstName + " " + middleName + " " + lastName;
return name;
}
public int getPlayerID()
{
playerID = count;
return playerID;
}
}
测试代码:
public class PaintballPlayerTest
{
public static void main (String [] args)
{
//Part 1 check constructor & toString --(make sure ID is working too)
PaintballPlayer sheldon = new PaintballPlayer ("Sheldon", "Lee", "Cooper");
PaintballPlayer leonard = new PaintballPlayer ("Leonard", "Hofstadter");
PaintballPlayer amy = new PaintballPlayer ("Amy", "Farrah", "Fowler");
System.out.println(sheldon);
System.out.println(leonard);
//Part 2 test getTotalPlayer --should be 3
System.out.println("The team has this many players " + PaintballPlayer.getTotalPlayers());
//Part 3 test recordShot
sheldon.recordShot(0);
sheldon.recordShot(1);
leonard.recordShot(0);
leonard.recordShot(0);
sheldon.recordShot(0);
sheldon.recordShot(1);
leonard.recordShot(2);
}
我的问题在于标有第 3 部分的区域。我感谢我得到的任何帮助。