/*
* 学生类
* */
public class Student {
private long no;
private float score;
private String name;
public void setNo(long no){
this.no = no;
}
public void setScore(float score){
this.score = score;
}
public void setName(String name){
this.name = name;
}
public long getNo(){
return no;
}
public float getScore(){
return score;
}
public String getName(){
return name;
}
public String isPass(){
if(score >= 60)
return"考试通过";
else
return"考试未通过";
}
public void printInfo(){
System.out.println(name+" "+isPass());
}
}/*
* 学生测试类
* */
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
public class StudentTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
HashMap<Long,Student> sl = new HashMap<Long,Student>();
boolean flag = true;
while(flag){
System.out.println("1.输入学生信息");
System.out.println("2.显示学生信息");
System.out.println("3.退出");
int op = sc.nextInt();
switch(op){
case 1:
System.out.println("输入学生人数");
int n = sc.nextInt();
Student s = new Student();
for(int i = 1;i <= n;++i){
System.out.println("输入第"+ i + "位同学的姓名");
String name = sc.next();
s.setName(name);
System.out.println("输入第"+ i + "位同学的学号");
long no = sc.nextLong();
s.setNo(no);
System.out.println("输入第"+ i + "位同学的成绩");
float score = sc.nextFloat();
s.setScore(score);
sl.put(no,s);
}
sc.nextLine();
break;
case 2:
System.out.println("输入需要查找的学生学号");
long no = sc.nextLong();
Student ss;
if(( ss = sl.get(no)) != null)
ss.printInfo();
else
System.out.println("查无此人");
sc.nextLine();
break;
case 3:
flag = false;
System.out.println("已退出");
sc.nextLine();
break;
default:
System.out.println("输入错误");
}
}
}
}
追问谢谢
本回答被提问者采纳