Day06_【学生管理系统】v1.0

【注】:功能描述
系统主页:选择身份,输入账号密码登录

教师账号:admin 密码:admin123
教师功能:查询学生列表、添加学生、修改学生、删除学生、返回主页、退出系统

学生账号:student 密码:student123
学生功能:查询学生列表、返回主页、退出系统

【注】:暂时采用数组实现数据存储。POP。未定义其他类,人员信息仅包含姓名,无修改账号密码等功能。其他功能日后完善。

Day06_【学生管理系统】v1.0
Day09_【学生管理系统】v1.1
Day11_【学生管理系统】v2.0

package com.csr;

import java.util.Scanner;

public class StudentManager {

	public static void main(String[] args) {
		StudentManager sysManager = new StudentManager();
		Scanner input = new Scanner(System.in);
		String[] stuList = {"丁丁", "迪西", "拉拉"};
		while (true) {
			boolean end1 = false;
			sysManager.begin();
			System.out.println("1:教师登录      2:学生登录");
			int choice = input.nextInt();
			boolean flag = sysManager.selectLogin(choice);
			while (true) {
				if (flag == true) {
					break;
				}
				sysManager.begin();
				flag = sysManager.selectLogin(choice);
			}	
			if (choice == 1) {
				while (true) {
					boolean end2 = false;
					System.out.println("1:学生列表      2:学生添加      3:学生修改      4:学生删除      5:返回主页      6:退出");
					int choice_t = input.nextInt();
					switch (choice_t) {
						case 1: // 查询
							showList(stuList);
							break;
						case 2: // 添加
							stuList = addStu(stuList);
							break;
						case 3: // 修改
							stuList = repStu(stuList);
							break;
						case 4: // 删除
							stuList = delStu(stuList); 	
							break;
						case 5:	// 返回
							end2 = true; 
							break;
						case 6: // 退出
							end1 = true;
							end2 = true;
							break;
						default:
							System.out.println("输入有误请重新输入");
							break;
					}
					if (end2) {
						break;
					}
				}
			} else {
				while (true) {
					boolean end2 = false;
					System.out.println("1:学生列表      2:返回主页      3:退出");
					int choice_s = input.nextInt();
					switch (choice_s) {
						case 1: // 查询
							showList(stuList);
							break;
						case 2: // 返回
							end2 = true;
							break;
						case 3: // 退出
							end1 = true;
							end2 = true;
							break;	
						default:
							System.out.println("输入有误请重新输入");
							break;
					}
					if (end2) {
						break;
					}
				}			
			}
			if (end1) {
				break;
			}
		}		
	}
	
	public static boolean tea_login() {
		String[] teacher = {"admin","admin123"};
		Scanner in = new Scanner(System.in);
		System.out.println("请输入您的账号");
		String idt = in.next();
		System.out.println("请输入您的密码");
		String keyt = in.next();
		if (idt.equals(teacher[0]) && keyt.equals(teacher[1])) {
			return true;
		} else {
			return false;
		}
	}
	
	public static boolean stu_login() {
		String[] student = {"student","student123"};
		Scanner in = new Scanner(System.in);
		System.out.println("请输入您的账号");
		String ids = in.next();
		System.out.println("请输入您的密码");
		String keys = in.next();
		if (ids.equals(student[0]) && keys.equals(student[1])) {
			return true;
		} else {
			return false;
		}
	}
	
	public static void showList(String[] l) {
		for (int i = 0; i < l.length; i++) {
			System.out.print("学生姓名:");
			System.out.println(l[i]);
		}
	}
	
	public static String[] addStu(String[] l) {
		String a[] = new String[l.length+1];
		System.out.println("请输入学生姓名:");
		String name = new Scanner(System.in).next();
		for (int i = 0; i < l.length; i++) {
			a[i] = l[i];
		}
		a[l.length] = name;
		System.out.println("添加成功");
		return a;
	}
	
	public static String[] repStu(String[] l) {
		String[] r = new String[l.length];
		System.out.println("请输入您需要修改的学生姓名");
		int count = 0;
		String name_old = new Scanner(System.in).next();
		for (int i = 0; i < l.length; i++) {
			if (l[i].equals(name_old)) {
				count++;
			}
		}
		if (count != 0) {
			System.out.println("请输重新确认该学生的姓名");
			String name_new = new Scanner(System.in).next();
			for (int i = 0; i < l.length; i++) {
				r[i] = l[i];
				if (l[i].equals(name_old)) {
					r[i]= name_new; 
				}
			}
			System.out.println("修改成功");
			return r;
		} else {
			System.out.println("没有查找到该学生");
			return l;
		}	
	}
	
	public static String[] delStu(String[] l) {
		String[] d = new String[l.length-1];
		System.out.println("请输入您需要删除的学生姓名");
		String name = new Scanner(System.in).next();
		int count = 0;
		for (int i = 0; i < l.length; i++) {
			if (l[i].equals(name)) {
				count++;
			}
		}
		if (count != 0) {
			for (int i = 0,j = 0; i < l.length; i++,j++) {
				if (!l[i].equals(name)) {
					d[j]= l[i]; 
				} else {
					j--;
				}
			}
			System.out.println("刪除成功");
			return d;
		} else {
			System.out.println("刪除失败,沒有找到对应的学生");
			return l;
		}		
	}
	
	public void begin() {
		System.out.println("*********************************");
		System.out.println("*******欢迎进入学生管理系统*******");
		System.out.println("*********************************");
	}
	
	public boolean selectLogin(int para) {
		boolean f = true;
		if (para == 1) {
			f = tea_login();
		} else if (para == 2) {
			f =  stu_login();
		} else {
			f = false;
		}
		return f;
	}

}
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页