用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

学生管理系统

2019-12-25 作者:小江爱酒窝举报

[java]代码库

package com.iflytek.studentmanagesystem.view;

import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

import com.iflytek.studentmanagesystem.pojo.Student;
import com.iflytek.studentmanagesystem.service.StudentService;
import com.iflytek.studentmanagesystem.service.impl.StudentServiceImpl;
import com.iflytek.studentmanagesystem.util.DateUtil;

public class MainClass {

	public static void main(String[] args) {
		while (true) {
			System.out.println("#######欢迎使用xxxx学生管理系统#######");
			System.out.println("1.增加学生信息\n2.删除学生信息\n3.修改学生信息\n4.查询学生信息\n0.退出系统\n请选择:");
			Scanner sc = new Scanner(System.in);
			int select = sc.nextInt();
			if (select == 0) {
				break;
			} else if (select == 1) {
				doAddStudent();
			} else if (select == 2) {
				doDeleteStudent();
			} else if (select == 3) {
				doModifyStudent();
			} else if (select == 4) {
				doQeuryStudent();
			} else {
				System.out.println("错误的功能代码!");
			}
		}
	}

	 
	private static void doAddStudent() {
		// TODO Auto-generated method stub
		StudentService service = new StudentServiceImpl();
		Scanner sc = new Scanner(System.in);
		System.out.println("输入要新增的学生的学号:");
		int number = sc.nextInt();
		if (service.queryByNumber(number) != null) {
			System.out.println("该学号对应的学生信息已经存在!");
			return;
		}
		sc.nextLine(); // 消除前面输入整数留下的回车符
		System.out.println("输入要新增的学生姓名:");
		String name = sc.nextLine();
		System.out.println("请输入要新增的学生性别:");
		String gender = sc.nextLine();
		System.out.println("请输入要新增的学生出生日期(如1990-1-1):");
		String birthday = sc.nextLine();
		System.out.println("请输入要新增的学生入学日期(如2019-9-1):");
		String entranceday = sc.nextLine();

		Student stu = new Student();
		stu.setNumber(number);
		stu.setName(name);
		stu.setGender(gender); 
		stu.setBirthday(DateUtil.str2date(birthday));
		stu.setEntranceday(DateUtil.str2date(entranceday));

		if (1 == service.add(stu)) {
			System.out.println("学生信息新增完成!");
		} else {
			System.out.println("学生信息增加失败!");
		}
	}


	private static void doDeleteStudent() {
		StudentService service = new StudentServiceImpl();
		Scanner sc = new Scanner(System.in);
		System.out.println("输入要删除的学生的学号:");
		int number = sc.nextInt();
		if (0 == service.delete(number)) {
			System.out.println("学生信息不存在,删除失败!");
		} else {
			System.out.println("学生信息删除完成!");
		}
	}

	private static void doModifyStudent() {
		StudentService service = new StudentServiceImpl();
		Scanner sc = new Scanner(System.in);
		System.out.println("输入要修改的学生的学号:");
		int number = sc.nextInt();
		if (service.queryByNumber(number) == null) {
			System.out.println("该学号对应的学生信息不存在,无法修改!");
			return;
		}
		sc.nextLine(); 
		System.out.println("输入要修改的学生新的姓名:");
		String name = sc.nextLine();
		System.out.println("请输入要修改的学生新的性别:");
		String gender = sc.nextLine();
		System.out.println("请输入要修改的学生新的出生日期(如1990-1-1):");
		String birthday = sc.nextLine();
		System.out.println("请输入要修改的学生新的入学日期(如2019-9-1):");
		String entranceday = sc.nextLine();

		Student stu = new Student();
		stu.setNumber(number);
		stu.setName(name);
		stu.setGender(gender);
		stu.setBirthday(DateUtil.str2date(birthday));
		stu.setEntranceday(DateUtil.str2date(entranceday));

		if (1 == service.modify(stu)) {
			System.out.println("学生信息修改完成!");
		} else {
			System.out.println("学生信息修改失败!");
		}

	}

	private static void doQeuryStudent() {
		StudentService service = new StudentServiceImpl();
		while (true) {
			System.out.println("1.按学号查询\n2.按姓名查询\n3.查看所有\n4.按年龄降序查看所有\n0.返回\n请选择:");
			Scanner sc = new Scanner(System.in);
			int select = sc.nextInt();
			if (select == 0) {
				break;
			} else if (select == 1) {
				System.out.println("输入要查询的学生的学号:");
				int number = sc.nextInt();
				Student stu = service.queryByNumber(number);
				if (stu == null) {
					System.out.println("未查询到相关信息");
				} else {
					System.out.println("查询到学生的信息:\n" + stu);
				}
			} else if (select == 2) {
				System.out.println("输入要查询的学生的姓名:");
				String name = sc.next();
				List<Student> stus = service.queryByName(name);
				if (stus.size() == 0) {
					System.out.println("未查询到相关信息");
				} else {
					System.out.println("查询到学生的信息:");
					for (int i = 0; i < stus.size(); i++) {
						System.out.println(stus.get(i));
					}
				}
			} else if (select == 3) {
				System.out.println("所有学生的信息:");
				List<Student> stus = service.queryAll();
				for (int i = 0; i < stus.size(); i++) {
					System.out.println(stus.get(i));
				}
			} else if (select == 4) {
				System.out.println("按年龄降序排列学生的信息:");
				List<Student> stus = service.queryAll();
				stus.sort(new Comparator<Student>() {

					@Override
					public int compare(Student o1, Student o2) {
						return (int) (o2.getBirthday().getTime() - o1.getBirthday().getTime());
					}
				});
				for (int i = 0; i < stus.size(); i++) {
					System.out.println(stus.get(i));
				}
			} else {
				System.out.println("错误的功能代码!");
			}
		}
	}

}

[代码运行效果截图]


学生管理系统

[源代码打包下载]




分享到:
更多

网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。