学生信息管理系统(简)
package com.java;
public class student {
private String sid;
private String name;
private String age;
private String address;
public student() {
}
public student(String sid, String name, String age, String address) {
this.sid = sid;
this.name = name;
this.age = age;
this.address = address;
}
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 getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
package com.java;
import java.util.Scanner;
import java.util.ArrayList;
public class student_system {
public static void main(String[] args) {
ArrayList<student> array = new ArrayList<student>();
while(true){
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("请输入你的选择:");
Scanner sc = new Scanner(System.in);
String line = sc.nextLine();
switch (line){
case "1":
add_student(array);
break;
case "2":
delete_student(array);
break;
case "3":
modify_student(array);
break;
case "4":
show_student(array);
break;
case "5":
System.exit(0);
default:
System.out.println("输入错误,请重新输入");
break;
}
}
}
public static void add_student(ArrayList<student> array) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入学生学号:");
String sid = sc.nextLine();
System.out.println("请输入学生姓名:");
String name = sc.nextLine();
System.out.println("请输入学生年龄:");
String age = sc.nextLine();
System.out.println("请输入学生地址:");
String address = sc.nextLine();
student s = new student();
s.setSid(sid);
s.setAge(age);
s.setName(name);
s.setAddress(address);
array.add(s);
System.out.println("添加学生成功");
}
public static void show_student(ArrayList<student> array) {
if(array.size()==0){
System.out.println("空");
return;
}
System.out.println("学号\t\t\t姓名\t\t\t年龄\t\t\t地址");
for(int i=0;i<array.size();i++){
System.out.println(array.get(i).getSid()+"\t"+array.get(i).getName()+"\t\t"+array.get(i).getAge()+"\t\t"+array.get(i).getAddress());
}
}
public static void delete_student(ArrayList<student> array) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入要删除学生的学号:");
String s = sc.nextLine();
System.out.println("确认是否删除该学生信息?yes/no");
String flag = sc.nextLine();
if(flag.equals("yes")){
for(int i=0;i<array.size();i++){
if(array.get(i).getSid().equals(s)){
array.remove(i);
}
}
System.out.println("删除学生成功");
}else {
System.out.println("已取消删除学生信息");
return;
}
}
public static void modify_student(ArrayList<student> array) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入要修改学生学号:");
String s = sc.nextLine();
System.out.println("新学号:");
String new_sid = sc.nextLine();
System.out.println("新姓名:");
String new_name = sc.nextLine();
System.out.println("新年龄:");
String new_age = sc.nextLine();
System.out.println("新地址:");
String new_address = sc.nextLine();
for(int i=0;i<array.size();i++){
if(array.get(i).getSid().equals(s)){
array.get(i).setSid(new_sid);
array.get(i).setName(new_name);
array.get(i).setAge(new_age);
array.get(i).setAddress(new_address);
}
}
System.out.println("修改成功");
}
}