import java.util.Vector; /*我下面功能的实现.直接传个对象就可以了是不是啊!但要如何实现输出*/
public class Tester
{
public static void main(String[] args)
{
Student[] student=new Student[6];
student[0]=new Student("S010" ,"匡麻子", 568.0f);
student[1]=new Student("S011" ,"里司", 561.0f);
student[2]=new Student("S012" ,"望物", 564.0f);
student[3]=new Student("S013" ,"找六", 567.0f);
student[4]=new Student("S014" ,"匡其实", 558.0f);
StudentManager sm=new StudentManager();
for(int i=0;i<5;i++)
{
sm.addStudent(student[i]);
}
sm.searchByid("S012");
sm.searchByid("S018");
sm.listAllStudent();
}
}
class StudentManager
{
private Vector vector=new Vector(100,10);
public void addStudent(Student stu) //添加学生信息
{
vector.add(stu);
}
public void listAllStudent() //显示所有学生信息
{
if(vector.size()==0)
{
System.out.println("没有任何学生信息");
return;
}
System.out.println("xuehao"+"\t"+"xingming"+"\t"+"chengji");
for(int i=0;i<vector.size();i++)
{
Student stu=(Student)vector.get(i);
System.out.println(stu.getid()+"\t"+stu.getname()+"\t"+"\t"+stu.getscore());
}
}
public Student searchByid(String id) //查找学生信息
{
if(id==null)
{
return null;
}
for(int i=0;i<vector.size();i++)
{
Student stu=(Student)vector.get(i);
if(id.equals(stu.getid()))
{
return stu;
}
}
return null; //请问这个语句的功能是什么。。。为什么缺它不可呢
}
public boolean delStudent(String id) // 通过指定学号删除学生信息
{
return false;
}
}
class Student //定义学生类
{
String id;
String name;
float score;
Student(String id,String name,float score)
{
this.id=id;
this.name=name;
this.score=score;
}
void setid(String a)
{
id=a;
}
String getid()
{
return id;
}
void setname(String b)
{
name=b;
}
String getname()
{
return name;
}
void setscore(float c)
{
score=c;
}
float getscore()
{
return score;
}
}
/*改写Tester类,测试StudentManager类的searchStudent方法
测试数据如下:
a>给出一个存在的数据:searchStudent(“S011”)
b>给出一个不存在的数据:searchStudent(“S018”)
*/
[此贴子已经被作者于2007-4-10 6:02:06编辑过]