package entity;
//学生类,属性为:姓名、性别、分数、年龄、班级 public class Student { private String name; private String gender; private int score; private int age; private String classes;
public Student(String name,String gender, int score,String
classes) {
this.name = name; this.gender = gender; this.score = score; this.classes = classes; }
public Student(String name, String gender, int age, int score)
{
this.name = name; this.gender = gender; this.age = age; this.score = score; }
public Student(String name, int score) { this.name = name; this.score = score; }
public Student(String name) { this.name = name; }
protected String getName() { return name; }
protected void setName(String name) {
this.name = name; }
protected int getAge() { return age; } protected void setAge(int age) { this.age = age; } protected String getGender() { return gender; }
protected void setGender(String gender) { this.gender = gender; }
protected int getScore() { return score; }
protected void setScore(int score) { this.score = score;
}
protected String getClasses() { return classes; }
protected void setClasses(String classes) { this.classes = classes; } }
第二题答案源码及运行效果截图: package entity;
import java.util.HashMap; import java.util.Scanner;
public class Homework2 {
public static void main(String[] args) { HashMap
Scanner input=new Scanner(System.in); Student stu1=new Student(\杨过\
Student stu2=new Student(\小龙女\ Student stu3=new Student(\张无忌\ Student stu4=new Student(\赵敏\
students.put(\杨过\ students.put(\小龙女\ students.put(\张无忌\ students.put(\赵敏\
System.out.println(\请输入学生姓名:\ String key=input.next();
if(students.containsKey(key)){ Student stu= students.get(key);
System.out.println(stu.getName()+\的成绩是:\ }
System.out.println(\所有学生的成绩是-----------\
for(Object value:students.values()){ Student stu=(Student) value;