学生信息管理系统设计
学生信息包括:学号,姓名,年龄,性别,出生年月,地址,电话, E-maiI等。试设计一学生信息管理系统,使之能提供以下功能: .
1、系统以菜单方式工作
2、学生信息录入功能- - -输入
3、学生信息浏览功能- --输出
4、学生信息查询功能一一算法
按学号查询
按姓名查询
5、学生信息的删除与修改(可选项)
网上有现成的代码,找一找就有了,可以参考下
import java.util.ArrayList;
import java.util.Scanner;
public class StudentManagementSystem {
private ArrayList<Student> studentList;
public StudentManagementSystem() {
studentList = new ArrayList<>();
}
public void showMenu() {
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("0. 退出系统");
System.out.println("=====================================");
}
public void addStudent() {
Scanner input = new Scanner(System.in);
System.out.println("请输入学生信息:");
System.out.print("学号:");
String id = input.nextLine();
System.out.print("姓名:");
String name = input.nextLine();
System.out.print("年龄:");
int age = input.nextInt();
input.nextLine();
System.out.print("性别:");
String gender = input.nextLine();
System.out.print("出生年月:");
String birthday = input.nextLine();
System.out.print("地址:");
String address = input.nextLine();
System.out.print("电话:");
String phone = input.nextLine();
System.out.print("E-mail:");
String email = input.nextLine();
Student student = new Student(id, name, age, gender, birthday, address, phone, email);
studentList.add(student);
System.out.println("学生信息录入成功!");
}
public void showStudentList() {
if (studentList.isEmpty()) {
System.out.println("没有学生信息!");
} else {
System.out.println("----------------- 学生信息列表 -----------------");
System.out.printf("%-10s%-10s%-5s%-5s%-15s%-20s%-15s%-30s\n",
"学号", "姓名", "年龄", "性别", "出生年月", "地址", "电话", "E-mail");
for (Student student : studentList) {
System.out.println(student);
}
System.out.println("-------------------------------------------------");
}
}
public void searchStudentById() {
Scanner input = new Scanner(System.in);
System.out.print("请输入要查询的学生学号:");
String id = input.nextLine();
boolean found = false;
for (Student student : studentList) {
if (student.getId().equals(id)) {
System.out.println(student);
found = true;
break;
}
}
if (!found) {
System.out.println("没有找到该学生!");
}
}
public void searchStudentByName() {
Scanner input = new Scanner(System.in);
System.out.print("请输入要查询的学生姓名:");
String name = input.nextLine();
boolean found = false;
for (Student student : studentList) {
if (student.getName().equals(name)) {
System.out.println(student);
found = true;
}
}
if (!found) {
System.out.println("没有找到该学生!");
}
}
public void deleteStudent() {
Scanner input = new Scanner(System.in);
System.out.print("请输入要删除的学生学号:");
String id = input.nextLine();
boolean found = false;
for (Student student : studentList) {
if (student.getId().equals(id)) {
studentList.remove(student);
System.out.println("学生信息删除成功!");
found = true;
break;
}
}
if (!found) {
System.out.println("没有找到该学生!");
}
}
public void updateStudent() {
Scanner input = new Scanner(System.in);
System.out.print("请输入要修改的学生学号:");
String id = input.nextLine();
boolean found = false;
for (Student student : studentList) {
if (student.getId().equals(id)) {
System.out.print("请输入学生姓名:");
String name = input.nextLine();
System.out.print("请输入学生年龄:");
int age = input.nextInt();
input.nextLine();
System.out.print("请输入学生性别:");
String gender = input.nextLine();
System.out.print("请输入学生出生年月:");
String birthday = input.nextLine();
System.out.print("请输入学生地址:");
String address = input.nextLine();
System.out.print("请输入学生电话:");
String phone = input.nextLine();
System.out.print("请输入学生E-mail:");
String email = input.nextLine();
student.setName(name);
student.setAge(age);
student.setGender(gender);
student.setBirthday(birthday);
student.setAddress(address);
student.setPhone(phone);
student.setEmail(email);
System.out.println("学生信息修改成功!");
found = true;
break;
}
}
if (!found) {
System.out.println("没有找到该学生!");
}
}
public void run() {
Scanner input = new Scanner(System.in);
int choice;
do {
showMenu();
System.out.print("请输入操作序号:");
choice = input.nextInt();
input.nextLine();
switch (choice) {
case 1:
addStudent();
break;
case 2:
showStudentList();
break;
case 3:
System.out.println("1. 按学号查询");
System.out.println("2. 按姓名查询");
System.out.print("请输入查询方式:");
int searchChoice = input.nextInt();
input.nextLine();
if (searchChoice == 1) {
searchStudentById();
} else if (searchChoice == 2) {
searchStudentByName();
} else {
System.out.println("输入有误!");
}
break;
case 4:
deleteStudent();
break;
case 5:
updateStudent();
break;
case 0:
System.out.println("谢谢使用!");
break;
default:
System.out.println("输入有误!");
break;
}
} while (choice != 0);
}
public static void main(String[] args) {
StudentManagementSystem system = new StudentManagementSystem();
system.run();
}
}
class Student {
private String id;
private String name;
private int age;
private String gender;
private String birthday;
private String address;
private String phone;
private String email;
public Student(String id, String name, int age, String gender, String birthday, String address, String phone, String email) {
this.id = id;
this.name = name;
this.age = age;
this.gender = gender;
this.birthday = birthday;
this.address = address;
this.phone = phone;
this.email = email;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return String.format("%-10s%-10s%-5d%-5s%-15s%-20s%-15s%-30s",
id, name, age, gender, birthday, address, phone, email);
}
}
类似的,修改就好,不会的话再问
http://t.csdn.cn/sjqUk
先创建一个 Student 类来表示学生对象,包括学号、姓名、年龄、性别、出生年月、地址、电话和邮箱等属性。
javaCopy Code
public class Student { private String id; private String name; private int age; private String gender; private Date birthdate; private String address; private String phone; private String email; // 构造方法、Getter 和 Setter 方法省略 }
创建一个主程序类,提供菜单功能,并处理用户输入。
javaCopy Code
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); StudentService service = new StudentServiceImpl(); 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("0. 退出系统"); System.out.print("请选择操作(0-5):"); int choice = scanner.nextInt(); switch (choice) { case 0: System.out.println("再见!"); System.exit(0); case 1: service.addStudent(); break; case 2: service.listStudents(); break; case 3: service.searchStudent(); break; case 4: service.updateStudent(); break; case 5: service.deleteStudent(); break; default: System.out.println("输入错误,请重新选择!"); } } } }
创建一个接口 StudentService 来定义学生信息管理的各种操作方法。
javaCopy Code
import java.util.List; public interface StudentService { void addStudent(); void listStudents(); void searchStudent(); void updateStudent(); void deleteStudent(); }
实现 StudentService 接口的具体实现类 StudentServiceImpl,并在其中使用 List 来存储学生信息。
javaCopy Code
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Scanner; public class StudentServiceImpl implements StudentService { private List studentList = new ArrayList<>(); private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); @Override public void addStudent() { Scanner scanner = new Scanner(System.in); System.out.print("请输入学号:"); String id = scanner.nextLine(); System.out.print("请输入姓名:"); String name = scanner.nextLine(); System.out.print("请输入性别(男/女):"); String gender = scanner.nextLine(); System.out.print("请输入年龄:"); int age = scanner.nextInt(); System.out.print("请输入出生日期(格式为 yyyy-MM-dd):"); String birthdateStr = scanner.next(); Date birthdate = null; try { birthdate = dateFormat.parse(birthdateStr); } catch (ParseException e) { System.out.println("日期格式错误,请重新输入!"); return; } scanner.nextLine(); // 读取换行符 System.out.print("请输入地址:"); String address = scanner.nextLine(); System.out.print("请输入电话号码:"); String phone = scanner.nextLine(); System.out.print("请输入电子邮件:"); String email = scanner.nextLine(); Student student = new Student(id, name, age, gender, birthdate, address, phone, email); studentList.add(student); System.out.println("添加成功!"); } @Override public void listStudents() { if (studentList.isEmpty()) { System.out.println("没有学生信息!"); } else { System.out.printf("%-10s%-10s%-5s%-5s%-10s%-20s%-15s%-20s%n", "学号", "姓名", "年龄", "性别", "出生日期", "地址", "电话", "电子邮件"); for (Student student : studentList) { System.out.printf("%-10s%-10s%-5d%-5s%-10s%-20s%-15s%-20s%n", student.getId, student.getName(), student.getAge(), student.getGender(), dateFormat.format(student.getBirthdate()), student.getAddress(), student.getPhone(), student.getEmail()); } } }
@Override public void searchStudent() { Scanner scanner = new Scanner(System.in); System.out.println("请选择查询方式:"); System.out.println("1. 按学号查询"); System.out.println("2. 按姓名查询"); int choice = scanner.nextInt(); scanner.nextLine(); // 读取换行符 switch (choice) { case 1: System.out.print("请输入学号:"); String id = scanner.nextLine(); Student studentById = findStudentById(id); if (studentById == null) { System.out.println("没有找到该学生信息!"); } else { displayStudentInfo(studentById); } break; case 2: System.out.print("请输入姓名:"); String name = scanner.nextLine(); List studentsByName = findStudentsByName(name); if (studentsByName.isEmpty()) { System.out.println("没有找到相关学生信息!"); } else { for (Student student : studentsByName) { displayStudentInfo(student); } } break; default: System.out.println("输入错误,请重新选择!"); } } @Override public void updateStudent() { Scanner scanner = new Scanner(System.in); System.out.print("请输入要修改的学生学号:"); String id = scanner.nextLine(); Student student = findStudentById(id); if (student == null) { System.out.println("没有找到该学生信息!"); return; } 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("6. 电话"); System.out.println("7. 电子邮件"); int choice = scanner.nextInt(); scanner.nextLine(); // 读取换行符 switch (choice) { case 1: System.out.print("请输入新的姓名:"); String name = scanner.nextLine(); student.setName(name); System.out.println("修改成功!"); break; case 2: System.out.print("请输入新的年龄:"); int age = scanner.nextInt(); student.setAge(age); System.out.println("修改成功!"); break; case 3: System.out.print("请输入新的性别(男/女):"); String gender = scanner.nextLine(); student.setGender(gender); System.out.println("修改成功!"); break; case 4: System.out.print("请输入新的出生日期(格式为 yyyy-MM-dd):"); String birthdateStr = scanner.next(); Date birthdate = null; try { birthdate = dateFormat.parse(birthdateStr); } catch (ParseException e) { System.out.println("日期格式错误,请重新输入!"); return; } student.setBirthdate(birthdate); System.out.println("修改成功!"); break; case 5: System.out.print("请输入新的地址:"); String address = scanner.nextLine(); student.setAddress(address); System.out.println("修改成功!"); break; case 6: System.out.print("请输入新的电话号码:"); String phone = scanner.nextLine(); student.setPhone(phone); System.out.println("修改成功!"); break; case 7: System.out.print("请输入新的电子邮件:"); String email = scanner.nextLine(); student.setEmail(email); System.out.println("修改成功!"); break; default: System.out.println("输入错误,请重新选择!"); } } @Override public void deleteStudent() { Scanner scanner = new Scanner(System.in); System.out.print("请输入要删除的学生学号:"); String id = scanner.nextLine(); Iterator iterator = studentList.iterator(); boolean found = false; while (iterator.hasNext()) { Student student = iterator.next(); if (student.getId().equals(id)) { iterator.remove(); found = true; break; } } if (found) { System.out.println("删除成功!"); } else { System.out.println("没有找到该学生信息!"); } } private Student findStudentById(String id) { for (Student student :studentList) { if (student.getId().equals(id)) { return student; } } return null; }
private List findStudentsByName(String name) { List students = new ArrayList<>(); for (Student student : studentList) { if (student.getName().equals(name)) { students.add(student); } } return students; } private void displayStudentInfo(Student student) { System.out.printf("%-10s%-10s%-5d%-5s%-10s%-20s%-15s%-20s%n", student.getId(), student.getName(), student.getAge(), student.getGender(), dateFormat.format(student.getBirthdate()), student.getAddress(), student.getPhone(), student.getEmail()); }
}
JAVA语言程序设计实验 (新)-学生信息管理系统
可以借鉴下
https://blog.csdn.net/qq_33550151/article/details/127552174
【课程设计】2小时学会JavaSwing课程设计-万能模板-图书管理系统-[你的课程我设计]
这里有个万能模板,你直接套就行了
首先,我们需要设计一个学生类来存储学生信息,代码如下:
public class Student {
private String id;
private String name;
private int age;
private String gender;
private String birth;
private String address;
private String phone;
private String email;
public Student(String id, String name, int age, String gender, String birth, String address, String phone, String email) {
this.id = id;
this.name = name;
this.age = age;
this.gender = gender;
this.birth = birth;
this.address = address;
this.phone = phone;
this.email = email;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getBirth() {
return birth;
}
public void setBirth(String birth) {
this.birth = birth;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
然后,我们需要设计一个管理系统类来实现学生信息的录入功能,代码如下:
import java.util.ArrayList;
import java.util.Scanner;
public class ManagementSystem {
private ArrayList<Student> students;
public ManagementSystem() {
students = new ArrayList<>();
}
public void addStudent() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入学生信息:");
System.out.print("学号:");
String id = scanner.next();
System.out.print("姓名:");
String name = scanner.next();
System.out.print("年龄:");
int age = scanner.nextInt();
System.out.print("性别:");
String gender = scanner.next();
System.out.print("出生年月:");
String birth = scanner.next();
System.out.print("地址:");
String address = scanner.next();
System.out.print("电话:");
String phone = scanner.next();
System.out.print("邮箱:");
String email = scanner.next();
students.add(new Student(id, name, age, gender, birth, address, phone, email));
System.out.println("学生信息录入成功!");
}
public void showMenu() {
System.out.println("1. 学生信息录入");
System.out.println("2. 学生信息查询");
System.out.println("3. 学生信息修改");
System.out.println("4. 学生信息删除");
System.out.println("5. 退出系统");
}
public void run() {
Scanner scanner = new Scanner(System.in);
while (true) {
showMenu();
System.out.print("请选择操作:");
int choice = scanner.nextInt();
switch (choice) {
case 1:
addStudent();
break;
case 2:
// 学生信息查询
break;
case 3:
// 学生信息修改
break;
case 4:
// 学生信息删除
break;
case 5:
System.out.println("谢谢使用,再见!");
System.exit(0);
default:
System.out.println("输入有误,请重新选择!");
}
}
}
public static void main(String[] args) {
ManagementSystem managementSystem = new ManagementSystem();
managementSystem.run();
}
}
以上代码实现了一个简单的学生信息管理系统,其中包括学生信息的录入功能,可以通过输入学生信息来添加学生。同时,还提供了菜单方式的操作,可以选择不同的功能。