概述
题目
测试类(main入口)
public class stu_Main {
public static void main(String[] args) {
Student s=new Student();
//调用接口初始化map,并接收
Map<String,List<String>> map=new HashMap<String,List<String>>();
map=s.Get_Initialise();
// Student s1=new Student("117333102","张三","98","44","22");
// s1.setSname("wang");
System.out.println("请选择你要进行的操作n 1.根据名字模糊查询相关学生信息n 2.查询系统中所有科目及不及格学生信息");
Scanner sc=new Scanner(System.in);
int opt=sc.nextInt();
switch(opt){
case 1:{
System.out.print("请输入学生的姓名:");
String name=sc.next();
String result=s.general_search(map,name);
System.out.print(result);
};break;
case 2:{
String result=s.check_all_flunk(map);
System.out.println(result);
};break;
default :{
System.out.println("系统关闭...");
};break;
}
sc.close();
}
}
Student对象类(提供类成员和方法)
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class Student {
private String Sno;
private String Sname;
private String ENscore;
private String MATHscore;
private String PEscore;
public Student(){ }
public Student( String Sno,
String Sname,
String ENscore,
String MATHscore,
String PEscore
){
this.Sno=Sno;
this.Sname=Sname;
this.ENscore=ENscore;
this.MATHscore=MATHscore;
this.PEscore=PEscore;
}
public String toString(){
return "[ "+Sno+" "+Sname+" "+ENscore+" "+MATHscore+" "+PEscore+" ]";
}
public String getSno() {
return Sno;
}
public void setSno(String sno) {
Sno = sno;
}
public String getSname() {
return Sname;
}
public void setSname(String sname) {
Sname = sname;
}
public String getENscore() {
return ENscore;
}
public void setENscore(String eNscore) {
ENscore = eNscore;
}
public String getMATHscore() {
return MATHscore;
}
public void setMATHscore(String mATHscore) {
MATHscore = mATHscore;
}
public String getPEscore() {
return PEscore;
}
public void setPEscore(String pEscore) {
PEscore = pEscore;
}
public Map<String, List<String>> Get_Initialise() {
// String[][] stuu={
// {"117333440333","张三","55","56","57"},
// {"117333440334","李四","58","59","60"},
// {"117333440335","王五","61","62","63"},
// {"117333440336","张三丰","64","65","66"},
// {"117333440337","张无忌","67","68","69"}
// };
Map<String,List<String>> map=new HashMap<String,List<String>>();
//1
List<String> list=new ArrayList<String>();
list.add("117333440333");// sno
list.add("42");// en
list.add("88");// math
list.add("99");// PE
map.put("张三",list);
//2
List<String> list2=new ArrayList<String>();
list2.add("117333440334");
list2.add("53");
list2.add("79");
list2.add("92");
map.put("李四",list2);
//3
List<String> list3=new ArrayList<String>();
list3.add("117333440335");
list3.add("21");
list3.add("84");
list3.add("85");
map.put("王五",list3);
//4
List<String> list4=new ArrayList<String>();
list4.add("117333440336");
list4.add("65");
list4.add("58");
list4.add("16");
map.put("张三丰",list4);
//5
List<String> list5=new ArrayList<String>();
list5.add("117333440337");
list5.add("97");
list5.add("95");
list5.add("34");
map.put("张无忌",list5);
// 返回初始化Map
return map;
}
public String check_all_flunk(Map<String, List<String>> mymap) {
Set<Map.Entry<String,List<String>>> entrySet=mymap.entrySet();
Iterator<Map.Entry<String,List<String>>> it=entrySet.iterator();
int count_EN=0,
count_Math=0,
count_PE=0;
String EN="英语成绩不及格的有:",
Math="高数成绩不及格的有:",
PE="体育成绩不及格的有:";
while(it.hasNext()){
Map.Entry<String,List<String>> map=it.next();
String name=map.getKey();
/* String Student_Number=map.getValue().get(0); */
double en_score=Double.parseDouble(map.getValue().get(1));
double math_score=Double.parseDouble(map.getValue().get(2));
double PE_score=Double.parseDouble(map.getValue().get(3));
if(en_score<60){
count_EN++;
EN+=name+" ";
}
if(math_score<60){
count_Math++;
Math+=name+" ";
}
if(PE_score<60){
count_PE++;
PE+=name+" ";
}
}
EN+="(共"+count_EN+"人)";
Math+="(共"+count_Math+"人)";
PE+="(共"+count_PE+"人)";
String result=EN+"n"+Math+"n"+PE;
return result;
}
public String general_search(Map<String, List<String>> mymap,String match_name){
Set<Map.Entry<String,List<String>>> entrySet=mymap.entrySet();
Iterator<Map.Entry<String,List<String>>> it=entrySet.iterator();
String str="为您搜索到以下信息:n";
while(it.hasNext()){
Map.Entry<String,List<String>> map=it.next();
String name=map.getKey();
if(name.contains(match_name)){
String Student_Number=" "+map.getValue().get(0)+" ";
String en_score=map.getValue().get(1)+" ";
String math_score=map.getValue().get(2)+" ";
String PE_score=map.getValue().get(3);
str+="[ "+name+Student_Number+en_score+math_score+PE_score+" ]n";
}
}
return str;
}
}
最后
以上就是俊秀帅哥为你收集整理的Map,List简写学生信息查询题目的全部内容,希望文章能够帮你解决Map,List简写学生信息查询题目所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复