JAVA_学生管理系统(纯java语言)





TestMain类
package StudentManagerSys;
import java.util.Scanner;
import StudentManagerSys.Data;
import StudentManagerSys.Student;
import StudentManagerSys.Teacher;
import StudentManagerSys.ManagerHandler;
import StudentManagerSys.SStudentHandler;
import StudentManagerSys.TTeacherHandler;
import StudentManagerSys.UI;
import StudentManagerSys.Util;

public class TestMain {
public static void main(String[] args) {
//初始化数据
Data data=new Data();
//接收用户输入操作:
Scanner scanner=new Scanner(System.in);
boolean flag=true;
while(flag){
//打印欢迎界面
UI.printLogin();
int bh=scanner.nextInt();
switch(bh){
case 1:
// 判断管理员的账号和密码是不是正确
for(int i=1;i<=3;i++){
boolean Mlogin=Util.Mlogin(data.getManager());
if(Mlogin){
i=3;
ManagerHandler mh=new ManagerHandler(data);
mh.handler();
data=mh.getData();
}else{
if(i==3){
flag=false;
System.out.println("今天登陆3次机会,用完,请想好账号和密码,明天再来尝试!");
}else{
System.out.println("登陆失败,请重新登陆");
}
}
}
break;
case 2:
// 判断教师的账号和密码是不是正确
for(int i=1;i<=3;i++){
Teacher teacher=Util.Tlogin(data.getTeachers());
if(teacher!=null){
i=3;
TTeacherHandler mh=new TTeacherHandler(data,teacher);
mh.handler();
data=mh.getData();
}else{
if(i==3){
flag=false;
System.out.println("今天登陆3次机会,用完,请想好账号和密码,明天再来尝试!");
}else{
System.out.println("登陆失败,请重新登陆");
}
}
}
break;
case 3:
// 判断学生的账号和密码是不是正确
for(int i=1;i<=3;i++){
Student student=Util.Slogin(data.getStudents());
if(student!=null){
i=3;
SStudentHandler mh=new SStudentHandler(data,student);
mh.handler();
data=mh.getData();
}else{
if(i==3){
flag=false;
System.out.println("今天登陆3次机会,用完,请想好账号和密码,明天再来尝试!");
}else{
System.out.println("登陆失败,请重新登陆");
}
}
}
break;
case 4:
System.out.println("4.退出系统");
flag=false;
break;
default:
System.out.println("输入有错误!请重新输入");
break;
}
}
}
}

UI界面类
package StudentManagerSys;
public class UI {
/**打印登陆界面 */
public static void printLogin(){
System.out.println("欢迎登陆华信智原学生管理系统");
System.out.println("1.管理员登录");
System.out.println("2.教师登录");
System.out.println("3.学生登录");
System.out.println("4.退出系统");
System.out.println("请输入选择操作编号:");
}
/**打印管理员界面 */
public static void printMLogin(){
System.out.println("管理员页面");
System.out.println("1.修改管理员的密码");
System.out.println("2.教师信息管理");
System.out.println("3.学生信息管理");
System.out.println("4.返回上一级");
System.out.println("请输入选择操作编号:");
}
/** 打印教师信息管理界面*/
public static void printTeacherCRUD(){
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("请输入选择操作编号:");
}
/** 打印学生信息管理界面 */
public static void printStudentCRUD(){
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("请输入选择操作编号:");
}
/**打印教师登陆成功的界面 */
public static void printTlogin(){
System.out.println("教师登陆成功界面");
System.out.println("1.修改密码");
System.out.println("2.查询个人信息");
System.out.println("3.学生信息的管理");
System.out.println("4.返回上一级");
System.out.println("请输入选择操作编号:");
}
/**打印学生登陆成功的界面 */
public static void printSlogin(){
System.out.println("学生登陆成功界面");
System.out.println("1.修改密码");
System.out.println("2.查询个人信息");
System.out.println("3.返回上一级");
System.out.println("请输入选择操作编号:");
}
}


管理员类:
package StudentManagerSys;
/**
* 管理员类
* @author Administrator
*/
public class Manager {
/**管理员的账户*/
private String count;
/**管理员的密码*/
private String password;
public String getCount() {
return count;
}
public void setCount(String count) {
this.count = count;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Manager() {
super();
// TODO Auto-generated constructor stub
}
public Manager(String count, String password) {
super();
this.count = count;
this.password = password;
}
}

教师类:

package StudentManagerSys;
/**
*教师类
*/
public class Teacher {
/**编号*/
private int id;
/**姓名*/
private String name;
/**密码*/
private String password;
/**年龄*/
private int age;
/**性别*/
private char sex;
/**地址*/
private String address;
/**手机号*/
private String phone;
/**邮箱*/
private String email;
/**专业*/
private String major;
/**学历*/
private String education;
/**职称*/
private String teaTitle;
public Teacher() {
super();
// TODO Auto-generated constructor stub
}
public Teacher(int id, String name, String password, int age, char sex,
String address, String phone, String email, String major,
String education, String teaTitle) {
super();
this.id = id;
this.name = name;
this.password = password;
this.age = age;
this.sex = sex;
this.address = address;
this.phone = phone;
this.email = email;
this.major = major;
this.education = education;
this.teaTitle = teaTitle;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
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;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public String getEducation() {
return education;
}
public void setEducation(String education) {
this.education = education;
}
public String getTeaTitle() {
return teaTitle;
}
public void setTeaTitle(String teaTitle) {
this.teaTitle = teaTitle;
}
@Override
public String toString() {
return this.id+"\t"+this.name+"\t"+this.password+"\t"+this.age+"\t"+this.sex+"\t"+this.address+"\t"+this.phone+"\t"+this.email+"\t"+this.major+"\t"+this.education+"\t"+this.teaTitle;
}
}

学生类
package StudentManagerSys;
/**
* 学生类
*/
public class Student {
/** 编号 */
private int id;
/** 姓名 */
private String name;
/** 年龄 */
private int age;
/** 性别 */
private char sex;
/** 密码 */
private String password;
/** 班级 */
private String stuClass;
/** 专业 */
private String major;
/** 学分 */
private double score;
/** 手机号 */
private String phone;
/** 邮箱 */
private String email;
/** 籍贯 */
private String address;

public Student() {
super();
// TODO Auto-generated constructor stub
}
public Student(int id, String name, int age, char sex, String password,
String stuClass, String major, double score, String phone,
String email, String address) {
super();
this.id = id;
this.name = name;
this.age = age;
this.sex = sex;
this.password = password;
this.stuClass = stuClass;
this.major = major;
this.score = score;
this.phone = phone;
this.email = email;
this.address = address;
}
public int getId() {
return id;
}
public void setId(int 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 char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getStuClass() {
return stuClass;
}
public void setStuClass(String stuClass) {
this.stuClass = stuClass;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
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;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public String toString() {
return this.id + "\t" + this.name + "\t" + this.age
+ "\t" + this.sex + "\t" + password + "\t"
+ stuClass + "\t" + major + "\t" + score
+ "\t" + phone + "\t" + email + "\t"
+ address ;
}
}


基本数据Data类
(这个类包括 管理员 教师们 学生们)
package StudentManagerSys;
/**
* 程序的数据
*/
public class Data {
/**管理员*/
private Manager manager;
/**教师们*/
private Teacher[] teachers;
/**学生们*/
private Student[] students;
public Data() {
init();
}
public Manager getManager() {
return manager;
}
public void setManager(Manager manager) {
this.manager = manager;
}
public Teacher[] getTeachers() {
return teachers;
}
public void setTeachers(Teacher[] teachers) {
this.teachers = teachers;
}
public Student[] getStudents() {
return students;
}
public void setStudents(Student[] students) {
this.students = students;
}
//准备初始数据
public void init(){
Manager manager=new Manager("manager","1111");
Teacher[] teachers=new Teacher[10];
for(int i=0;i
teachers[i]=new Teacher(i, "name"+i, "password"+i, 20+i, '女', "address"+i, "phone"+i, "email"+i, "major"+i, "education"+i, "teaTitle"+i);
}
Student[] students=new Student[10];
for(int i=0;i
students[i]=new Student(i, "name"+i, 10+i, '男', "password"+i, "stuClass"+i, "major"+i, 60+i, "phone"+i, "email"+i, "address"+i);
}
setManager(manager);
setTeachers(teachers);
setStudents(students);
}
}

Util工具类(登录验证):
Util----> 在这个工具类中添加
管理员登陆验证的方法
教师登陆验证的方法
学生登陆验证的方法
package StudentManagerSys;
import java.util.Scanner;
import StudentManagerSys.Manager;
import StudentManagerSys.Student;
import StudentManagerSys.Teacher;
/**工具类: 一般工具类中的方法是使用static来修饰 一调用方便 */
public class Util {
/** 管理员登陆验证 */
public static boolean Mlogin(Manager manager){
Scanner scan=new Scanner(System.in);
System.out.println("请你输入一个账号");
String count=scan.next();
// 首先判断账号是不是存在
if(manager.getCount().equals(count)){//如果存在继续输入密码
System.out.println("请你输入一个密码");
String password=scan.next();
if(manager.getPassword().equals(password)){//密码正确 返回true
return true;
}
}
return false;
}
/** 教师登陆验证,由于教师有多个,如果教师登陆成功 ,那么通过验证要已经登陆的教师找到并且返回 */
public static Teacher Tlogin(Teacher[] teachers){
Scanner scan=new Scanner(System.in);
System.out.println("请输入教师的编号:");
int id=scan.nextInt();
Teacher teacher= findTeacherById(teachers,id) ;// 通过输入的id去到数据teachers中该编号对应teacher
if(teacher!=null){
System.out.println("请输入教师的密码");
String password=scan.next();
if(teacher.getPassword().equals(password)){//如果密码相等将当前登陆教师信息返回
return teacher;
}
}
return null;
}
/** 根据编号找教师*/
public static Teacher findTeacherById(Teacher[] teachers,int id) {
Teacher teacher=null;
for(int i=0;i
if(teachers[i].getId()==id){
teacher=teachers[i];
return teacher;
}
}
return null;
}
/** 学生登陆验证, 由于学生有多个,如果学生登陆成功 ,那么通过验证要已经登陆的学生找到并且返回 */
public static Student Slogin(Student[] students){
Scanner scan=new Scanner(System.in);
System.out.println("请输入学生的编号:");
int id=scan.nextInt();
Student student= findStudentById(students,id) ;// 通过输入的id去到数据students中该编号对应student
if(student!=null){
System.out.println("请输入学生的密码");
String password=scan.next();
if(student.getPassword().equals(password)){//如果密码相等将当前登陆学生信息返回
return student;
}
}
return null;
}
/** 根据编号找学生*/
public static Student findStudentById(Student[] students,int id) {
Student student=null;
for(int i=0;i
if(students[i].getId()==id){
student=students[i];
return student;
}
}
return null;
}
}
工具测试类:UtilTest
package StudentManagerSys;
import StudentManagerSys.Manager;
import StudentManagerSys.Student;
import StudentManagerSys.Teacher;
import StudentManagerSys.Util;
/**
* 工具测试类 :测试工具类是否可靠
* @author Administrator
*/
public class UtilTest {
public static void main(String[] args) {
testMlogin();
testTlogin();
testSlogin();
}
public static void testMlogin() {
Manager manager=new Manager("manager","1111");
boolean flag=Util.Mlogin(manager);//???
System.out.println(flag?"登陆成功":"用户或密码不正确");
}
public static void testTlogin() {
//创建一个教师的模拟数据
Teacher[] teachers=new Teacher[10];
for(int i=0;i
teachers[i]=new Teacher(i, "name"+i, "password"+i, 20+i, '女', "address"+i, "phone"+i, "email"+i, "major"+i, "education"+i, "teaTitle"+i);
}
Teacher teacher=Util.Tlogin(teachers);
System.out.println(teacher==null?"登陆失败":"登陆成功");
}
public static void testSlogin() {
//创建一个学生的模拟数据
Student[] students=new Student[10];
for(int i=0;i
students[i]=new Student(i, "name"+i, 10+i, '男',"password"+i , "stuClass"+i, "major"+i, 80+i, "phone"+i, "email"+i, "address"+i);
}
Student student=Util.Slogin(students);
System.out.println(student==null?"登陆失败":"登陆成功");
}
}
教师操作工具类TeacherDao类
package StudentManagerSys;
import java.util.Arrays;
import java.util.Scanner;
import StudentManagerSys.Teacher;
/**
* teacher 操作的工具方法
*/
public class TeacherDao {
/**查询所有老师信息 */
public void showAll(Teacher[] teachers) {
System.out.println("所有老师的信息如下:");
System.out.println("编号\t姓名\t密码\t年龄\t性别\t地址\t手机号\t邮箱\t专业\t学历\t职称");
for(int i=0;i
System.out.println(teachers[i]);
}
System.out.println("请选择需要操作的教师编号:");
}
/**根据老师的编号删除某个老师的 信息 */
public Teacher[] deleteById(Teacher[] teachers,int id) {
Teacher[] teachers1=new Teacher[]{};
for(int i=0;i
if(teachers[i].getId()!=id){//将不需要的数据 放入新的数组
teachers1=Arrays.copyOf(teachers1, teachers1.length+1);// 扩充新数组
teachers1[teachers1.length-1]=teachers[i];// 在扩充的位置上加入元素
}
}
return teachers1;
}
/** 根据老师新的信息来修改老师的信息 */
public Teacher[] updateById(Teacher[] teachers,int id) {
for(int i=0;i
if(teachers[i].getId()==id){//找到需要修改的teacher
Scanner scan=new Scanner(System.in);
boolean flag=true;//true--> 循环继续, false ---->循环结束
while(flag){
System.out.println("编号\t姓名\t密码\t年龄\t性别\t地址\t手机号\t邮箱\t专业\t学历\t职称");
System.out.println(teachers[i]);
System.out.println("############教师的信息###########");
System.out.println("########1.教师的姓名##########");
System.out.println("########2.教师的密码##########");
System.out.println("########3.教师的年龄##########");
System.out.println("请选择需要修改的内容编号(退出输入-1)");
int number=scan.nextInt();
switch(number){
case 1:
System.out.println("请你输入新的教师的名字");
String name=scan.next();
teachers[i].setName(name);
break;
case 2:
System.out.println("请你输入新的教师的密码");
String password=scan.next();
teachers[i].setPassword(password);
break;
case 3:
System.out.println("请你输入新的教师的年龄");
int age=scan.nextInt();
teachers[i].setAge(age);
break;
case -1:
flag=false;
break;
default:
System.out.println("你输入的编号有错误:请重新输入");
break;
}
}
}
}
return teachers;
}
/** 添加一个老师的信息*/
public Teacher[] add(Teacher[] teachers) {
System.out.println("添加新的教师的新学年");
Teacher teacher=new Teacher();
Scanner scan=new Scanner(System.in);
System.out.println("请你输入一个教师的编号:");
int id=scan.nextInt();
teacher.setId(id);
System.out.println("请你输入一个教师的姓名:");
String name=scan.next();
teacher.setName(name);
System.out.println("请你输入一个教师的密码:");
String password=scan.next();
teacher.setPassword(password);
System.out.println("请你输入一个教师的年龄:");
int age=scan.nextInt();
teacher.setAge(age);
System.out.println("请你输入一个教师的性别:");
char sex=scan.next().charAt(0);
teacher.setSex(sex);
System.out.println("请你输入一个教师的地址:");
String address=scan.next();
teacher.setAddress(address);
System.out.println("请你输入一个教师的手机号:");
String phone=scan.next();
teacher.setPhone(phone);
System.out.println("请你输入一个教师的邮箱:");
String email=scan.next();
teacher.setEmail(email);
System.out.println("请你输入一个教师的专业:");
String major=scan.next();
teacher.setMajor(major);
System.out.println("请你输入一个教师的学历:");
String education=scan.next();
teacher.setEducation(education);
System.out.println("请你输入一个教师的职称:");
String teaTitle=scan.next();
teacher.setTeaTitle(teaTitle);
teachers=Arrays.copyOf(teachers, teachers.length+1);
teachers[teachers.length-1]=teacher;
return teachers;
}
}
教师操作工具类的测试类TeacherDaoTest类:
package StudentManagerSys;
import java.util.Arrays;
import java.util.Scanner;
import StudentManagerSys.TeacherDao;
import StudentManagerSys.Teacher;

public class TeacherDaoTest {

public static void main(String[] args) {
testShowall();
testdeleleById();
testupdateById();
testadd();
}
public static void testShowall() {
TeacherDao dao=new TeacherDao();
Teacher[] teachers=new Teacher[10];
for(int i=0;i
teachers[i]=new Teacher(i, "name"+i, "password"+i, 20+i, 'Ů', "address"+i, "phone"+i, "email"+i, "major"+i, "education"+i, "teaTitle"+i);
}
dao.showAll(teachers);
}
public static void testdeleleById() {
TeacherDao dao=new TeacherDao();
Teacher[] teachers=new Teacher[10];
for(int i=0;i
teachers[i]=new Teacher(i, "name"+i, "password"+i, 20+i, 'Ů', "address"+i, "phone"+i, "email"+i, "major"+i, "education"+i, "teaTitle"+i);
}
dao.showAll(teachers);
Scanner scan=new Scanner(System.in);
int teacherid=scan.nextInt();
teachers=dao.deleteById(teachers, teacherid);
//System.out.println(teacherid+","+teachers.length+","+Arrays.toString(teachers));
dao.showAll(teachers);
}
public static void testupdateById() {
TeacherDao dao=new TeacherDao();
Teacher[] teachers=new Teacher[10];
for(int i=0;i
teachers[i]=new Teacher(i, "name"+i, "password"+i, 20+i, 'Ů', "address"+i, "phone"+i, "email"+i, "major"+i, "education"+i, "teaTitle"+i);
}
dao.showAll(teachers);
Scanner scan=new Scanner(System.in);
int teacherid=scan.nextInt();
teachers=dao.updateById(teachers, teacherid);
//System.out.println(teacherid+","+teachers.length+","+Arrays.toString(teachers));
dao.showAll(teachers);
}
public static void testadd() {
TeacherDao dao=new TeacherDao();
Teacher[] teachers=new Teacher[10];
for(int i=0;i
teachers[i]=new Teacher(i, "name"+i, "password"+i, 20+i, 'Ů', "address"+i, "phone"+i, "email"+i, "major"+i, "education"+i, "teaTitle"+i);
}
dao.showAll(teachers);
teachers=dao.add(teachers);
//System.out.println(teacherid+","+teachers.length+","+Arrays.toString(teachers));
dao.showAll(teachers);
}
}
学生操作工具类StudentDao
package StudentManagerSys;
import java.util.Arrays;
import java.util.Scanner;
import StudentManagerSys.Student;
/**
* student 操作的工具方法
*/
public class StudentDao {
/** 查询所有学生信息*/
public void showAll(Student[] students){
System.out.println("所有学生的信息如下:");
System.out.println("编号\t姓名\t年龄\t性别\t密码\t班级\t专业\t学分\t手机号\t邮箱\t地址");
for(int i=0;i
System.out.println(students[i]);
}
System.out.println("请选择需要操作的学生编号:");
}
/** 根据学生的编号删除某个学生的 信息*/
public Student[] deleteById(Student[] students,int id){
Student[] students1=new Student[]{};
for(int i=0;i
if(students[i].getId()!=id){//将不需要的数据 放入新的数组
students1=Arrays.copyOf(students1, students1.length+1);// 扩充新数组
students1[students1.length-1]=students[i];// 在扩充的位置上加入元素
}
}
return students1;
}
/**根据学生新的信息来修改学生的信息 */
public Student[] updateById(Student[] students,int id){
for(int i=0;i
if(students[i].getId()==id){//找到需要修改的student
Scanner scan=new Scanner(System.in);
boolean flag=true;//true--> 循环继续, false ---->循环结束
while(flag){
System.out.println("编号\t姓名\t年龄\t性别\t密码\t班级\t专业\t学分\t手机号\t邮箱\t地址");
System.out.println(students[i]);
System.out.println("############学生的信息###########");
System.out.println("########1.学生的姓名##########");
System.out.println("########2.学生的密码##########");
System.out.println("########3.学生的年龄##########");
System.out.println("请选择需要修改的内容编号(退出输入-1)");
int number=scan.nextInt();
switch(number){
case 1:
System.out.println("请你输入新的学生的名字");
String name=scan.next();
students[i].setName(name);
break;
case 2:
System.out.println("请你输入新的学生的密码");
String password=scan.next();
students[i].setPassword(password);
break;
case 3:
System.out.println("请你输入新的学生的年龄");
int age=scan.nextInt();
students[i].setAge(age);
break;
case -1:
flag=false;
break;
default:
System.out.println("你输入的编号有错误:请重新输入");
break;
}
}
}
}
return students;
}
/**添加一个学生的信息 */
public Student[] add(Student[] students) {
System.out.println("编号\t姓名\t年龄\t性别\t密码\t班级\t专业\t学分\t手机号\t邮箱\t地址");
System.out.println("添加新的学生的信息");
Student student=new Student();
Scanner scan=new Scanner(System.in);
System.out.println("请你输入一个学生的编号:");
int id=scan.nextInt();
student.setId(id);
System.out.println("请你输入一个学生的姓名:");
String name=scan.next();
student.setName(name);
System.out.println("请你输入一个学生的年龄:");
int age=scan.nextInt();
student.setAge(age);
System.out.println("请你输入一个学生的性别:");
char sex=scan.next().charAt(0);
student.setSex(sex);
System.out.println("请你输入一个学生的密码:");
String password=scan.next();
student.setPassword(password);
System.out.println("请你输入一个学生的班级:");
String stuClass=scan.next();
student.setStuClass(stuClass);
System.out.println("请你输入一个学生的专业:");
String major=scan.next();
student.setMajor(major);
System.out.println("请你输入一个学生的学分:");
double score=scan.nextDouble();
student.setScore(score);
System.out.println("请你输入一个学生的手机号:");
String phone=scan.next();
student.setPhone(phone);
System.out.println("请你输入一个学生的邮箱:");
String email=scan.next();
student.setEmail(email);
System.out.println("请你输入一个学生的地址:");
String address=scan.next();
student.setAddress(address);
students=Arrays.copyOf(students, students.length+1);
students[students.length-1]=student;
return students;
}
}
学生操作工具类的测试类StudentDaoTest类
package StudentManagerSys;
import java.util.Arrays;
import java.util.Scanner;
import StudentManagerSys.StudentDao;
import StudentManagerSys.Student;

public class StudentDaoTest {
public static void main(String[] args) {
testShowall();
testdeleleById();
testupdateById();
testadd();
}
public static void testShowall() { //testShowall()
StudentDao dao=new StudentDao();
Student[] Students=new Student[10];
for(int i=0;i
Students[i]=new Student(i, "name"+i, 10+i, '男', "password"+i, "stuClass"+i, "major"+i, 60+i, "phone"+i, "email"+i, "address"+i);
}
dao.showAll(Students);
}
public static void testdeleleById() { //testdeleleById()
StudentDao dao=new StudentDao();
Student[] Students=new Student[10];
for(int i=0;i
Students[i]=new Student(i, "name"+i, 10+i, '男', "password"+i, "stuClass"+i, "major"+i, 60+i, "phone"+i, "email"+i, "address"+i);
}
dao.showAll(Students);
Scanner scan=new Scanner(System.in);
int Studentid=scan.nextInt();
Students= dao.deleteById(Students, Studentid);
//System.out.println(Studentid+","+Students.length+","+Arrays.toString(Students));
dao.showAll(Students);
}
public static void testupdateById() { //testupdateById()
StudentDao dao=new StudentDao();
Student[] Students=new Student[10];
for(int i=0;i
Students[i]=new Student(i, "name"+i, 10+i, '男', "password"+i, "stuClass"+i, "major"+i, 60+i, "phone"+i, "email"+i, "address"+i);
}
dao.showAll(Students);
Scanner scan=new Scanner(System.in);
int Studentid=scan.nextInt();
Students= dao.updateById(Students, Studentid);
//System.out.println(Studentid+","+Students.length+","+Arrays.toString(Students));
dao.showAll(Students);
}
public static void testadd() { //testadd()
StudentDao dao=new StudentDao();
Student[] Students=new Student[10];
for(int i=0;i
Students[i]=new Student(i, "name"+i, 10+i, '男', "password"+i, "stuClass"+i, "major"+i, 60+i, "phone"+i, "email"+i, "address"+i);
}
dao.showAll(Students);
Students= dao.add(Students);
//System.out.println(Studentid+","+Students.length+","+Arrays.toString(Students));
dao.showAll(Students);
}
}
ManagerHandle类
package StudentManagerSys;
import java.util.Scanner;
import StudentManagerSys.Data;
import StudentManagerSys.UI;
public class ManagerHandler {
private Data data;
public ManagerHandler(Data data) {
super();
this.data = data;
}
public void handler(){
Scanner scan=new Scanner(System.in);
boolean flag=true;
while(flag){
//打印输出管理的界面
UI.printMLogin();
int bh=scan.nextInt();
switch(bh){
case 1:
updatePassword();//修改密码
break;
case 2:
TeacherHandler thandler=new TeacherHandler(data);//教师管理系统
thandler.handler();
setData(thandler.getData());
break;
case 3:
StudentHandler shandler=new StudentHandler(data);//学生管理系统
shandler.handler();
setData(shandler.getData());
break;
case 4:
flag=false;//返回上一级
break;
default:
System.out.println("输入错误!请重新输入");
break;
}
}
}
private void updatePassword() {
System.out.println("请你输入原始密码");
Scanner scan=new Scanner(System.in);
String password=scan.next();
if(data.getManager().getPassword().equals(password)){
System.out.println("请你输入新的密码");
String password2=scan.next();
data.getManager().setPassword(password2);
}else{
System.out.println("密码错误! 不能修改");
}
}

public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
}
StudentHandle类
package StudentManagerSys;
import java.util.Scanner;
import StudentManagerSys.StudentDao;
import StudentManagerSys.Data;
import StudentManagerSys.UI;

public class StudentHandler {
private Data data;
public StudentHandler(Data data) {
super();
this.data = data;
}
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
public void handler(){
Scanner scan=new Scanner(System.in);
boolean flag=true;
StudentDao dao=new StudentDao();
while(flag){
//打印输出管理的界面
UI.printStudentCRUD();
int bh=scan.nextInt();
switch(bh){
case 1:
dao.showAll(data.getStudents()); //查询
break;
case 2:
data.setStudents(dao.add(data.getStudents())); //添加
break;
case 3:
System.out.println("请输入学生编号");
int id=scan.nextInt();
data.setStudents(dao.updateById(data.getStudents(), id)); //修改
break;
case 4:
System.out.println("请输入学生编号");
int id2=scan.nextInt();
data.setStudents(dao.deleteById(data.getStudents(), id2)); //删除
break;
case 5:
flag=false;
break;
default:
System.out.println("输入错误!请重新输入");
break;
}
}
}
}
SStudentHandle类
package StudentManagerSys;
import java.util.Scanner;
import StudentManagerSys.TeacherDao;
import StudentManagerSys.Data;
import StudentManagerSys.Student;
import StudentManagerSys.Teacher;
import StudentManagerSys.UI;

public class SStudentHandler {
private Data data;
private Student student;
//getset方法
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
//构造方法
public SStudentHandler(Data data, Student student) {
super();
this.data = data;
this.student = student;
}


public void handler(){
Scanner scan=new Scanner(System.in);
boolean flag=true;
while(flag){
//打印输出管理的界面
UI.printSlogin();
int bh=scan.nextInt();
switch(bh){
case 1:
updatePassword();//修改密码
break;
case 2:
showStudent();//查询个人信息
break;
case 3:
flag=false;//返回上一级
break;
default:
System.out.println("输入错误!请重新输入");
break;
}
}
}
private void showStudent() {
System.out.println("编号\t姓名\t年龄\t性别\t密码\t班级\t专业\t学分\t手机号\t邮箱\t地址");
System.out.println(student);
}

private void updatePassword() {
System.out.println("请你输入原始密码");
Scanner scan=new Scanner(System.in);
String password=scan.next();
if(student.getPassword().equals(password)){
System.out.println("请你输入新的密码");
String password2=scan.next();
student.setPassword(password2);
tongbudata();//密码修改后同步数据 即保证 teacher 中数据与对应 data中的teacher的数据保持一致
}else{
System.out.println("密码错误! 不能修改");
}
}
/**
* 修改教师密码的数据同步到 data中
*/
private void tongbudata() {
for(int i=0;i
if(student.getId()==data.getStudents()[i].getId()){
data.getStudents()[i]=student;
return;
}
}
}
}

TeacherHandle类
package StudentManagerSys;
import java.util.Scanner;
import StudentManagerSys.TeacherDao;
import StudentManagerSys.Data;
import StudentManagerSys.UI;

public class TeacherHandler {
private Data data;
//构造
public TeacherHandler(Data data) {
super();
this.data = data;
}
//getset方法
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}

public void handler(){
Scanner scan=new Scanner(System.in);
boolean flag=true;
TeacherDao dao=new TeacherDao();
while(flag){
//打印输出管理的界面
UI.printTeacherCRUD();
int bh=scan.nextInt();
switch(bh){
case 1:
dao.showAll(data.getTeachers()) ;//查询
break;
case 2:
data.setTeachers(dao.add(data.getTeachers())); //添加
break;
case 3:
System.out.println("请输入教师编号");
int id=scan.nextInt();
data.setTeachers(dao.updateById(data.getTeachers(), id)); //修改
break;
case 4:
System.out.println("请输入教师编号");
int id2=scan.nextInt();
data.setTeachers(dao.deleteById(data.getTeachers(), id2)); //删除
break;
case 5:
flag=false;
break;
default:
System.out.println("输入错误!请重新输入");
break;
}
}
}
}

TTeacherHandle类
package StudentManagerSys;
import java.util.Scanner;
import StudentManagerSys.TeacherDao;
import StudentManagerSys.Data;
import StudentManagerSys.Teacher;
import StudentManagerSys.UI;

public class TTeacherHandler {
//属性
private Data data;
private Teacher teacher;
//构造
public TTeacherHandler(Data data,Teacher teacher) {
super();
this.data = data;
this.teacher=teacher;
}
//getset方法
public Teacher getTeacher() {
return teacher;
}
public void setTeacher(Teacher teacher) {
this.teacher = teacher;
}
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
//方法
public void handler(){
Scanner scan=new Scanner(System.in);
boolean flag=true;
TeacherDao dao=new TeacherDao();
while(flag){
//打印输出管理的界面
UI.printTlogin();
int bh=scan.nextInt();
switch(bh){
case 1:
updatePassword();//修改密码
break;
case 2:
showTeacher();//查询个人信息
break;
case 3:
StudentHandler shandler=new StudentHandler( data );//学生系统
shandler.handler();
setData(shandler.getData());
break;
case 4:
flag=false;//返回上一级
break;
default:
System.out.println("输入错误!请重新输入");
break;
}
}
}
private void showTeacher() {
System.out.println("编号\t姓名\t密码\t年龄\t性别\t地址\t手机号\t邮箱\t专业\t学历\t职称");
System.out.println(teacher);
}
private void updatePassword() {
System.out.println("请你输入原始密码");
Scanner scan=new Scanner(System.in);
String password=scan.next();
if(teacher.getPassword().equals(password)){
System.out.println("请你输入新的密码");
String password2=scan.next();
teacher.setPassword(password2);
tongbudata();//密码修改后同步数据 即保证 teacher 中数据与对应 data中的teacher的数据保持一致
}else{
System.out.println("密码错误! 不能修改");
}
}
/**
* 修改教师密码的数据同步到 data中
*/
private void tongbudata() {
for(int i=0;i
if(teacher.getId()==data.getTeachers()[i].getId()){
data.getTeachers()[i]=teacher;
return;
}
}
}
}



你可能感兴趣的:(JAVA初级编程案例)