我正在尝试编译以下简单代码并收到错误,错误类接口或枚举预期请帮助我找出我的错误。
public class Scores
{
public static final int maxEntries =5;
int numEntries;
protected GameEntry[] entries;
public Scores()
{
entries = new GameEntry[maxEntries];
numEntries = 0;
}
public String toString()
{
String s = "[";
for (int i=0 ; i < numEntries; i++)
{
if (i > 0) s = ","; // separate entries by commas
s = s + entries[i].toString() ;
}
return s + "]";
}
public void add(GameEntry e)
{
entries[numEntries]=e;
numEntries++;
}
public void add(GameEntry e)
{
int newScore = e.getScore();
if (numEntries == maxEntries)
{
if (newScore <= entries[numEntries-l].getScore())
return;
}
else
return numEntries++;
int i = numEntries-l;
for ( ; (i >= 1) && (newScore > entries[i-1].getScore()); i--)
entries[i] = entries[i-1];
entries[i] = e;
}
}
public static void main(String args[])
{
Scores s1=new Scores();
GameEntry e1=new GameEntry("Paul",750);
s1.add(e1);
GameEntry e2=new GameEntry("John",770);
s1.add(e2);
system.out.println(s1.toString());
GameEntry e1=new GameEntry("Sam",600);
s1.add(e1);
GameEntry e2=new GameEntry("Raj",800);
s1.add(e2);
system.out.println(s1.toString());
GameEntry e1=new GameEntry("Gobi",550);
s1.add(e1);
GameEntry e2=new GameEntry("Raj",580);
s1.add(e2);
system.out.println(s1.toString());
}