packagelianxi;importjava.util.*;importjava.util.Scanner;publicclasszuoye{publicstaticvoidmain(String[]args){ArrayLista=newArrayList();StuManagesm=newStuManage();Scannerin...
package lianxi;
import java.util.*;
import java.util.Scanner;
public class zuoye
{
public static void main(String[] args)
{
ArrayList a=new ArrayList();
StuManage sm=new StuManage();
Scanner input=new Scanner(System.in);
System.out.println("请选贼您要进行的操作:");
System.out.println("1.添加学生信息:");
System.out.println("2.查询学生成绩:");
System.out.println("3.查询学生编号:");
System.out.println("4.删除学生信息:");
String operType=input.next();
while(true)
{
if(operType.equals("1"))
{
sm.addStu();
}
else if(operType.equals("2"))
{
sm.showScore();
}
else if(operType.equals("3"))
{
sm.showstuNo();
}
else if(operType.equals("4"))
{
sm.delStu();
}
else if(operType.equals("0"))
{
System.exit(0);
}
}
}
}
class StuManage
{
ArrayList a=null;
public StuManage()
{
a=new ArrayList();
}
public void addStu()
{
Scanner input=new Scanner(System.in);
System.out.println("请输入学生编号:");
String stuNo=input.next();
System.out.println("请输入学生成绩:");
float score=input.nextFloat();
Stu stu=new Stu(stuNo,score);
a.add(stu);
}
public void showScore()
{
Scanner input=new Scanner(System.in);
System.out.println("请输入学生编号:");
String stuNo=input.next();
for(int i=0;i
{
Stu stu=(Stu)a.get(i);
if(stu.getStuNo().equals(stuNo))
{
System.out.println("学生成绩是:"+stu.getScore());
}
}
}
public void showstuNo()
{
Scanner input=new Scanner(System.in);
System.out.println("请输入学生成绩:");
float score=input.nextFloat();
for(int i=0;i
{
Stu stu=(Stu)a.get(i);
if(stu.getScore()==score)
{
System.out.println("学生的编号是:"+stu.getStuNo());
}
}
}
public void Count()
{
int good=0;
int bad=0;
for(int i=0;i
{
Stu stu=(Stu)a.get(i);
if(stu.getScore()>60&&stu.getScore()<=100)
{
good+=1;
}else if(stu.getScore()<60&&stu.getScore()>=0)
{
bad+=1;
}
}
System.out.println("及格学生人数是:"+good+" 不及格人数是:"+bad);
}
public void delStu()
{
Scanner input=new Scanner(System.in);
System.out.println("请输入学生的编号:");
String stuNo=input.next();
for(int i=0;i
{
Stu stu=(Stu)a.get(i);
if(stu.getStuNo().equals(stuNo))
{
a.remove(i);
System.out.println("----------已删除信息---------");
}
}
}
}
class Stu
{
private String stuNo;
private float score;
public String getStuNo() {
return stuNo;
}
public void setStuNo(String stuNo) {
this.stuNo = stuNo;
}
public float getScore() {
return score;
}
public void setScore(float score) {
this.score = score;
}
public Stu(String stuNo,float score)
{
this.stuNo=stuNo;
this.score=score;
}
}
记得之前写还好用,重新写突然找不出问题了,新手刚学
展开