新手学习,还没学过泛型,所以不用泛型.程序运行到添加对象到HashMap时,就报NullPointerException...
/*
* 用HashMap 做学生管理
*/
import java.util.*;
public class Studentmanager {
public static void main(String[] args) {
Stumanager man=new Stumanager();
Scanner reader=new Scanner(System.in);
while(true) //选择界面
{
System.out.println("1:添加学生");
System.out.println("2:显示学生信息");
System.out.println("3:修改学生成绩");
System.out.println("4:删除学生");
System.out.println("5:退出");
int rd=reader.nextInt();
if(rd==1) //添加学生
{
System.out.println("输入学号");
int stuno=reader.nextInt();
System.out.println("输入姓名");
String name=reader.next();
System.out.println("输入学生成绩");
int score=reader.nextInt();
Student stu1=new Student(stuno,name,score);
man.add(stuno,stu1);
}
else if(rd==2) //显示学生信息
{
System.out.println("输入学号");
int stuno=reader.nextInt();
man.info(stuno);
}
else if(rd==3) //修改成绩
{
System.out.println("输入学号");
int stuno=reader.nextInt();
Student stu=(Student) man.hm1.get(stuno);
System.out.println("原成绩为"+stu.getScore());
System.out.println("输入学生新成绩");