- 前言:该文章是学习3个小时写出来的学生信息管理系统,该系统是最基础的面向过程程序,本周会有MySQL的
GUI 程序呈上,现在只是公布该系统源码,有不懂的可以留言。
Student.java 文件
package SIMS;
public class Student {
private String sid;
private String name;
private String age;
private String grade;
public Student(){
}
public Student(String sid, String name, String age, String grade) {
this.sid = sid;
this.name = name;
this.age = age;
this.grade = grade;
}
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 getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
}
Student Manager 文件
package SIMS;
import java.util.ArrayList;
import java.util.Scanner;
public class StudentManager {
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、退出");
Scanner sc = new Scanner((System.in));
String line = sc.nextLine();
switch (line) {
case "1":
addStudent(array);
break;
case "2":
deleteStudent(array);
break;
case "3":
updateStudent(array);
break;
case "4":
findAllStudent(array);
break;
case "5":
System.exit(0);
}
}
}
public static void addStudent(ArrayList<Student> array) {
Scanner sc = new Scanner(System.in);
System.out.print("请输入学生学号:");
String sid = sc.nextLine();
System.out.print("请输入学生姓名:");
String name = sc.nextLine();
System.out.print("请输入学生年龄:");
String age = sc.nextLine();
System.out.print("请输入学生班级信息:");
String grade = sc.nextLine();
Student s = new Student();
s.setSid(sid);
s.setAge(age);
s.setName(name);
s.setGrade(grade);
array.add(s);
System.out.println("添加学生成功");
}
public static void findAllStudent(ArrayList<Student> array) {
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.getGrade());
}
}
public static void deleteStudent(ArrayList<Student> array) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入你想要删除的学号");
String sid = sc.nextLine();
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 updateStudent(ArrayList<Student> array) {
Scanner sc = new Scanner(System.in);
System.out.print("请输入学生学号:");
String sid = sc.nextLine();
System.out.print("请输入学生姓名:");
String name = sc.nextLine();
System.out.print("请输入学生年龄:");
String age = sc.nextLine();
System.out.print("请输入学生班级信息:");
String grade = sc.nextLine();
Student s = new Student();
s.setSid(sid);
s.setAge(age);
s.setName(name);
s.setGrade(grade);
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("修改学生成功");
}
}
}
|