当前位置: 代码迷 >> Java相关 >> [求助]转换问题
  详细解决方案

[求助]转换问题

热度:121   发布时间:2006-11-13 16:41:35.0
[求助]转换问题

小弟在JAVA论坛上出来乍到...还请各位多多包含.......

import java.util.*;
import java.io.*;

public class 第九题
{

private ArrayList c = new ArrayList();

public 第九题()
{
Student nick = new Student("Nick", "47043081", 100);
Student hebe = new Student("Hebe", "47043082", 100);
Student susan = new Student("Susan", "47043083", 100);

c.add(nick);
c.add(hebe);
c.add(susan);

printCollection(c);

Remove("47043083");

printCollection(c);

}

public void Remove(String sId)
{
for (int i = 0; i < c.size(); i++)
if ((Student)(c.get(i)).id.equals(sId))
c.remove(i);

}

public static void main(String[] args)throws IOException
{

new 第九题();
new BufferedReader(new InputStreamReader(System.in)).readLine();

}

private void printCollection(Collection c)
{
System.out.println("-------------------------");
Iterator it = c.iterator();

while (it.hasNext())
{
System.out.println(it.next());
}

System.out.println();
}
}
class Student
{
private String name;
public String id;
private int score;

public Student(String Name, String Id, int Score)
{
name = Name;
id = Id;
score = Score;
}

public String toString()
{
String s = id + "同学的姓名是:" + name + "\n成绩是:" + score;
return s;
}

public String xuehao()
{
return id;
}

public double sScore()
{
return score;
}
}

错误 1 在“Object”中找不到方法“xuehao()” C:\Documents and Settings\Administrator\桌面\Test\Test\Program.jsl 36 17 Test


但是我已经向下进行能够了强行转换.....
各位帮小弟看看...谢了

搜索更多相关的解决方案: private  public  import  JAVA  

----------------解决方案--------------------------------------------------------
Sorry错误信息粘错了

错误 1 在类型“Object”中无法找到字段“id” C:\Documents and Settings\Administrator\桌面\Test\Test\Program.jsl 36 17 Test

----------------解决方案--------------------------------------------------------

你的红色部份,括号能匹配吗


----------------解决方案--------------------------------------------------------
不能么?我强行向下转换成STUDENT行...不行么?
----------------解决方案--------------------------------------------------------
  相关解决方案