欢迎来到天天文库
浏览记录
ID:35351919
大小:66.15 KB
页数:11页
时间:2019-03-23
《学士后java集合框架和泛型习题答案》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、packageentity;//学生类,属性为:姓名、性别、分数、年龄、班级publicclassStudent{privateStringname;privateStringgender;privateintscore;privateintage;privateStringclasses;publicStudent(Stringname^Stringgender^intscore,Stringclasses){this・name=name;this・gender=gender;this.score=score;this.classes=
2、classes;}publicStudent(Stringname,Stringgenderintage?intscore)this・name=name;thiSegender=gender;this.age=age;this.score=score;publicStuden^(Stringname,intscore){this・name=name;this.score=score;}publicStudent(Stringname){this・name=name;}protectedStringgetName(){returnname
3、;}protectedvoidsetName(Stringname){this>name=name;protectedintgetAge(){returnage;}protectedvoidsetAge(intage){this.age=age;}protectedStringgetGender(){returngender;}protectedvoidsetGender(Stringgender){this・gender=gender;}protectedintgetScore(){returnscore;}protectedvoids
4、etScore(intscore){this.score=score;}protectedStringgetClasses(){returnclasses;}protectedvoidsetClasses(Stringclasses){this.classes=classes;}}第二题答案源码及运行效果截图:packageentity;importjava.util.HashMap;importjava・util・Scanner;publicclassHomework2{publicstaticvoidmain(String[]args
5、){HashMapstudents=newHashMap6、2);students・put("张无忌",stu3);students.put("赵敏”,stu4);System・out.println(M请输入学生姓名:H);Stringkey=input・next();if(students・containsKey(key)){Studentstu=students.get(key);System.out・println(stu・getName()+"的成绩是:H+stu.getScore());}System.out・println(M所有学生的成绩是”);for(Objectvalue:st7、udents・values()){Studentstu=(Studerit)value;System.out.println(stu・getName()+"的成绩是:"+stu.getScore());}请输入学生姓名:杨过杨过的成绩是:95所有学生的成绩是杨过的成绩是:95小龙女的成绩是:99赵敏的成绩是:90张无忌的成绩是:88第三题答案源码及运行效杲截图:packageentity;importjava・util・*;publicclassHomeworks{publicstaticvoidmain(String[]args){Li8、stcStudent〉listl=newArrayList();Listlist2=newArrayList();List
6、2);students・put("张无忌",stu3);students.put("赵敏”,stu4);System・out.println(M请输入学生姓名:H);Stringkey=input・next();if(students・containsKey(key)){Studentstu=students.get(key);System.out・println(stu・getName()+"的成绩是:H+stu.getScore());}System.out・println(M所有学生的成绩是”);for(Objectvalue:st
7、udents・values()){Studentstu=(Studerit)value;System.out.println(stu・getName()+"的成绩是:"+stu.getScore());}请输入学生姓名:杨过杨过的成绩是:95所有学生的成绩是杨过的成绩是:95小龙女的成绩是:99赵敏的成绩是:90张无忌的成绩是:88第三题答案源码及运行效杲截图:packageentity;importjava・util・*;publicclassHomeworks{publicstaticvoidmain(String[]args){Li
8、stcStudent〉listl=newArrayList();Listlist2=newArrayList();List
此文档下载收益归作者所有