package studentmy;
import java.security.PublicKey;
import java.util.ArrayList;
import java.util.Scanner;
public class student {
private String sid;
private String name;
private String age;
private String room;
public student() {
}
public student(String sid, String name, String age, String room) {
super();
this.sid = sid;
this.name = name;
this.age = age;
this.room = room;
}
public String getSid() {
return sid;
}
public void setSid(String sid) {
this.sid = sid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getRoom() {
return room;
}
param room the room to set
public void setRoom(String room) {
this.room = room;
}
public static void main(String[] args) {
ArrayListarray=new ArrayList();
while (true) {
Scanner sc=new Scanner(System.in);
System.out.println(“--------欢迎来到学生管理系统--------”);
System.out.println(“1 添加学生”);
System.out.println(“2 删除学生”);
System.out.println(“3 修改学生”);
System.out.println(“4 查看所有学生”);
System.out.println(“5 退出”);
System.out.println(“请输入你的选择:”);
String a=sc.next();
switch (a) {
case “1”:
addstudent(array);
break;
case “2”:
dropsrudent(array);
break;
case “3”:
mofiltstudent(array);
break;
case “4”:
fingallstudent(array);
break;
case “5”:
System.out.println(“谢谢使用”);
System.exit(0);
}
}
}
public static void addstudent(ArrayListarrayList) {
Scanner scanner=new Scanner(System.in);
System.out.println(“请输入学生学号”);
String sidString=scanner.next();
System.out.println(“请输入学生姓名”);
String nameString=scanner.next();
System.out.println(“请输入学生年龄”);
String ageString=scanner.next();
System.out.println(“请输入学生住址”);
String rommString=scanner.next();
student s = new student();
s.setSid(sidString);
s.setName(nameString);
s.setAge(ageString);
s.setRoom(rommString);
arrayList.add(s);
System.out.println(“添加学生成功”);
}
public static void dropsrudent(ArrayListarray) {
Scanner sc= new Scanner(System.in);
System.out.println(“请输入你要删除学生的学号”);
String sid=sc.next();
for (int i = 0; i < array.size(); i++) {
student s=array.get(i);
if (s.getSid().equals(sid)) {
array.remove(i);
break;
}
}
System.out.println(“删除成功”);
}
public static void mofiltstudent(ArrayListarray) {
Scanner sc= new Scanner(System.in);
System.out.println(“请输入你要修改学生的学号”);
String sid=sc.next();
System.out.println(“请输入学生新姓名”);
String nameString=sc.next();
System.out.println(“请输入学生新年龄”);
String ageString=sc.next();
System.out.println(“请输入学生新住址”);
String rommString=sc.next();
student s = new student();
s.setSid(sid);
s.setName(nameString);
s.setAge(ageString);
s.setRoom(rommString);
for (int i = 0; i < array.size(); i++) {
student student=array.get(i);
if (student.getSid().equals(sid)) {
array.set(i, s);
break;
}
}
System.out.println(“修改成功”);
}
public static void fingallstudent(ArrayListarray) {
if (array.size()==0) {
System.out.println(“无信息,请先添加信息再查询”);
return;
}
System.out.println(“学号\t姓名\t年龄\t住址”);
for (int i = 0; i < array.size(); i++) {
student s=array.get(i);
System.out.println(s.getSid()+“\t”+s.getName()+“\t”+s.getAge()+“岁\t”+s.getRoom());
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)