學(xué)生管理系統(tǒng)之添加學(xué)生功能
//添加學(xué)生
public static void addStudent(ArrayList<Student> array) {
//創(chuàng)建鍵盤(pán)錄入對(duì)象
Scanner sc = new Scanner(System.in);
System.out.println("請(qǐng)輸入學(xué)生學(xué)號(hào)");
String id = sc.nextLine();
System.out.println("請(qǐng)輸入學(xué)生姓名");
String name = sc.nextLine();
System.out.println("請(qǐng)輸入學(xué)生年齡");
String age = sc.nextLine();
System.out.println("請(qǐng)輸入學(xué)生居住地");
String address = sc.nextLine();
//創(chuàng)建學(xué)生對(duì)象
Student s = new Student();
s.setId(id);
s.setName(name);
s.setAge(age);
s.setAddress(address);
//把學(xué)生對(duì)象作為元素添加到集合
array.add(s);
//給出提示
System.out.println("添加學(xué)生成功");
}