102 lines
2.1 KiB
Java
102 lines
2.1 KiB
Java
import java.util.HashMap;
|
||
|
||
/**
|
||
* @Classname Student
|
||
* @Description TODO
|
||
* @Date 2024/7/25 上午9:07
|
||
* @Created by 杨旭飞
|
||
*/
|
||
|
||
public class Student {
|
||
|
||
/**
|
||
* 学生编号
|
||
*/
|
||
private Integer stuId;
|
||
/**
|
||
* 学生姓名
|
||
*/
|
||
private String stuName;
|
||
/**
|
||
* 年龄
|
||
*/
|
||
private Integer stuAge;
|
||
/**
|
||
* 学生性别
|
||
*/
|
||
private String stuSex;
|
||
/**
|
||
* 学生成绩
|
||
*/
|
||
private Integer stuScore;
|
||
|
||
|
||
public Integer getStuId() {
|
||
return stuId;
|
||
}
|
||
|
||
public void setStuId(Integer stuId) {
|
||
this.stuId = stuId;
|
||
}
|
||
|
||
public String getStuName() {
|
||
return stuName;
|
||
}
|
||
|
||
public void setStuName(String stuName) {
|
||
this.stuName = stuName;
|
||
}
|
||
|
||
public Integer getStuAge() {
|
||
return stuAge;
|
||
}
|
||
|
||
public void setStuAge(Integer stuAge) {
|
||
this.stuAge = stuAge;
|
||
}
|
||
|
||
public String getStuSex() {
|
||
return stuSex;
|
||
}
|
||
|
||
public void setStuSex(String stuSex) {
|
||
this.stuSex = stuSex;
|
||
}
|
||
|
||
public Integer getStuScore() {
|
||
return stuScore;
|
||
}
|
||
|
||
public void setStuScore(Integer stuScore) {
|
||
this.stuScore = stuScore;
|
||
}
|
||
|
||
public Student() {
|
||
}
|
||
|
||
public Student(Integer stuId, String stuName, Integer stuAge, String stuSex, Integer stuScore) {
|
||
this.stuId = stuId;
|
||
this.stuName = stuName;
|
||
this.stuAge = stuAge;
|
||
this.stuSex = stuSex;
|
||
this.stuScore = stuScore;
|
||
}
|
||
|
||
|
||
public static void main(String[] args) {
|
||
// 创建HashMap对象。(10 分)
|
||
HashMap<Integer, String> hashMap = new HashMap<>();
|
||
// 创建两个学生对象。(10 分)
|
||
String nameone = "yangpeng";
|
||
String nametwo = "yangxufei";
|
||
// 保存到HashMap集合中,键为学生编号,值为学生对象。(30 分)
|
||
String nameonename = hashMap.put(1, nameone);
|
||
String nametwoname = hashMap.put(2, nametwo);
|
||
|
||
// 三种方式遍历输出集合中的元素信息。(30 分)
|
||
System.out.println(hashMap);
|
||
System.out.println(nameonename);
|
||
System.out.println(nametwoname);
|
||
}
|
||
}
|