JAVA程序注释(学生信息管理中的两段程序)

来源:百度知道 编辑:UC知道 时间:2024/06/25 22:07:53
//查找方法
public void search(int k) 构造查找方法
{
boolean exist=false;
int low=0;
int high=StuInf.size()-1;
while(low<=high)
{
mid=(high+low)/2;
StudentInf a1=(StudentInf) StuInf.elementAt(mid);
if(a1.getStuNo()==k)
{
SI=(StudentInf) StuInf.elementAt(mid);
String x = String.valueOf(SI.getStuNo());
exist=true;
input1.setText(SI.getname());
input1.selectAll();
input2.setText("0"+x);
input3.setText(SI.getClassNo());
if(SI.getLevel()==-1)
input4.setText("未参加考试");
else
{
String y = String.valueOf(SI.getLevel());
input4.setText(y);
}
break;
}
else if(a1.getStuNo()<k)
low=mid+1;
else
high=mid-1;
}
if(exist==false)
{
input1.setText("无此学号学生信息");
input1.selectAll();
}
}
//添加方法
public void Insert(StudentInf q)
{
int i=0;

if(StuInf.isEmpty()==true) <

public void search(int k) 构造查找方法
{//二分法查找
boolean exist=false;
int low=0;
int high=StuInf.size()-1;
while(low<=high) //当开头指针与结尾指针重合时,查找结束
{
mid=(high+low)/2;//中间指针
StudentInf a1=(StudentInf) StuInf.elementAt(mid);
if(a1.getStuNo()==k)
{//如果找到学生
SI=(StudentInf) StuInf.elementAt(mid);
String x = String.valueOf(SI.getStuNo());
exist=true;
input1.setText(SI.getname());
input1.selectAll();
input2.setText("0"+x);
input3.setText(SI.getClassNo());
if(SI.getLevel()==-1)
input4.setText("未参加考试");
else
{
String y = String.valueOf(SI.getLevel());
input4.setText(y);
}
break;
}//以上部分用于显示学生信息
else if(a1.getStuNo()<k)
low=mid+1;//重新设定low 与high指针
else
high=mid-1;
}
if(exist==false)
{
input1.setText("无此学号学生信息");
input1.selectAll();//找不到学生
}
}
//添加方法
public void Insert(Stud