java学生教师管理系统
- 在项目下创建的包有(记得项目里导包和API):
- **controller包下内容**(客服业务)
- controlStudent类
- controlTeacher类
- **dao包下内容**(库管业务)
- daoperson类
- daoStudent类
- daoTeacher类
- **domin包下内容**(定义成员变量)
- person类
- Student类
- Teacher类
- **service包下内容**(业务员业务)
- serviceStudent类
- serviceTeacher类
- **entry包**(里面是主方法main--运行类)
- infomanagerentry类
- 实现效果
这个是java版本的代码版本,已在控制台上完美运行,用的编写软件是idea.希望大家可以参考和交流,我也会慢慢把更完善注释和优化版本发布出来.管理系统里管理了学生和教师,可以根据个人需要只管理一个或者交流发出来
在项目下创建的包有(记得项目里导包和API):
controller包
dao包
domin包
service包
entry包
controller包下内容(客服业务)
controlStudent类
public class controlStudent {
private static serviceStudent serviceStudent = new serviceStudent();
private static Scanner sc = new Scanner(System.in);
public static void start() {
Scanner sc = new Scanner(System.in);
lo:
while (true) {
System.out.println("**##$$$$$欢迎进入学生管理系统$$$$$##**");
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("请输入您的选择:");
String chioce = sc.next();//输入选择
switch (chioce) {
case "1":
addstudent();//增加学生
break;
case "2":
deletestudent();//删除学生");
break;
case "3":
//修改学生");
updatestudent();
break;
case "4":
//查看学生");
findAllStudent();
break;
case "5":
System.out.println("退出");
break lo;
default:
System.out.println("你的输入不对,请重新输入");
break;
}
}
}
private static void deletestudent() {
String delid=inputstudentid();
serviceStudent.deletestudent(delid);
System.out.println("删除成功");
}
public static void updatestudent() {
//serviceStudent serviceStudent=new serviceStudent();
//ArrayList<Student> students= serviceStudent.findAllStudent();
String updateid=inputstudentid();
Student newstu = inputstudentinfo(updateid);
serviceStudent.updatestudent(updateid,newstu);
System.out.println("修改成功");
}
public static Student inputstudentinfo(String sid) {
/* System.out.println("请输入学号:");
String sid=sc.next();*/
System.out.println("请输入学生姓名:");
String name = sc.next();
System.out.println("请输入学生年龄:");
int age = sc.nextInt();
System.out.println("请输入学生生日:");
String birthday = sc.next();
Student stu = new Student(sid, name, age, birthday);
// Student student=Student(stu.setSid(),stu.setName(),stu.setAge(),stu.setBirthday());
/* stu.setName(name);
stu.setAge(age);
stu.setBirthday(birthday);*/
return stu;
}
public static void findAllStudent() {
//serviceStudent serviceStudent=new serviceStudent();
Student[] students= serviceStudent.findallStudent();
if (students==null){
System.out.println("查无学生信息, 请添加后重试");
return;//直接结束这句
}//else语句作用,可不写
System.out.println("学号"+"\t\t"+"姓名"+"\t\t"+"年龄"+"\t\t"+"生日");
for (int i = 0; i <students.length; i++) {
Student students1=students[i];
System.out.println(students1.getSid()+"\t"+students1.getName()+"\t\t"+students1.getAge()+"\t\t"+students1.getBirthday());
}
}
public static void addstudent() {
serviceStudent serviceStudent = new serviceStudent();
Scanner sc = new Scanner(System.in);
String sid;
while (true) {
System.out.println("请输入学号:");
sid = sc.next();
boolean flag = serviceStudent.isExists(sid);
if (flag) {
System.out.println("学号已被占用,请重新输入:");
} else {
break;
}
}
System.out.println("请输入姓名:");
String name = sc.next();
System.out.println("请输入年龄:");
int age = sc.nextInt();
System.out.println("请输入生日:");
String birthday = sc.next();
Student stu = new Student(sid, name, age, birthday);
boolean result = serviceStudent.addStudent(stu);
if (result) {
System.out.println("添加成功");
} /*else {
System.out.println("添加失败");
}*/
}
public static String inputstudentid( ){
String sid;
while (true){
System.out.println("请输入学生id:");
sid = sc.next();
boolean exists=serviceStudent.isExists(sid);
if (!exists){
System.out.println("你输入的id不存在,请重新输入:");
}else {
break;
}
}
return sid;
}
}
controlTeacher类
public class controlTeacher {
private static Scanner sc = new Scanner(System.in);
public void start() {
lo:
while (true) {
System.out.println("**##$$$$$欢迎进入教师管理系统$$$$$##**");
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("请输入您的选择:");
String chioce = sc.next();//输入选择
switch (chioce) {
case "1":
addteacher();//增加教师
break;
case "2":
deleteteacher();//删除教师");
break;
case "3":
//修改教师");
updateteacher();
break;
case "4":
//查看教师");
findteacher();
break;
case "5":
System.out.println("退出");
break lo;
default:
System.out.println("你的输入不对,请重新输入");
break;
}
}
}
public void deleteteacher() {
String delsid=inputstudentid();
serviceTeacher.deleteteacher(delsid);
System.out.println("删除成功");
}
public void updateteacher() {
String updatesid=inputstudentid();
Teacher newtea=inputteacherinfo(updatesid);
serviceTeacher.updateteacher(updatesid,newtea);
System.out.println("更新成功");
}
private Teacher inputteacherinfo(String sid) {
System.out.println("请输入姓名:");
String name = sc.next();
System.out.println("请输入年龄:");
int age = sc.nextInt();
System.out.println("请输入生日:");
String birthday = sc.next();
Teacher tea = new Teacher(sid, name, age, birthday);
return tea;
}
public static String inputstudentid( ){
String sid;
while (true){
System.out.println("请输入教师工号:");
sid = sc.next();
boolean exists=serviceTeacher.isExists(sid);
if (!exists){
System.out.println("你输入的id不存在,请重新输入:");
}else {
break;
}
}
return sid;
}
public void findteacher() {查看要用一个数组接收信息
Teacher[] teachers= serviceTeacher.findteacher();
if (teachers==null){ //数组为空判定
System.out.println("没有教师信息,请输入后重试");
return;
} //不为空输出业务层接收的数组,并打印
System.out.println("工号"+"\t\t"+"姓名"+"\t\t"+"年龄"+"\t\t"+"生日");
for (int i = 0; i < teachers.length; i++) {
Teacher teacher=teachers[i];
System.out.println(teacher.getSid()+"\t"+teacher.getName()+"\t\t"+teacher.getAge()+"\t\t"+teacher.getBirthday());
}
}
public void addteacher() {
serviceTeacher serviceStudent = new serviceTeacher();
Scanner sc = new Scanner(System.in);
String sid;
while (true) {
System.out.println("请输入工号:");
sid = sc.next();
boolean flag = serviceStudent.isExists(sid);
if (flag) {
System.out.println("工号已被占用,请重新输入:");
} else {
break;
}
}
System.out.println("请输入姓名:");
String name = sc.next();
System.out.println("请输入年龄:");
int age = sc.nextInt();
System.out.println("请输入生日:");
String birthday = sc.next();
Teacher tea = new Teacher(sid, name, age, birthday);
boolean result = serviceTeacher.addteacher(tea);
if (result) {
System.out.println("添加成功");
}
}
}
dao包下内容(库管业务)
daoperson类
public abstract class daoperson {
/*new abstract daoStudent(ArrayList<Student> list);
public int getindex(String sid ) {
int index=-1; //客服的添加判定
for (int i = 0; i <list.size(); i++) {
Student student= list.get(i);
if (student!=null&&sid.equals(student.getSid())){
index=i;
break;
}
}
return index;
}*/
}
daoStudent类
public class daoStudent extends daoperson {
public ArrayList<Student> list = new ArrayList<>();
//添加学生信息
public boolean addstudent(Student stu) {
list.add(stu);
return true;
}
//查看学生信息
public Student[] findAllStudent() {
Student[] stu=new Student[list.size()];
for (int i = 0; i < stu.length; i++) {
stu[i]=list.get(i);
}
return stu;
}
//更新学生信息
public void updatestudent(String updateid,Student newstu) {
int index=getindex(updateid);
list.set(index,newstu);
}
//遍历索引
public int getindex(String sid ) {
int index=-1; //客服的添加判定
for (int i = 0; i <list.size(); i++) {
Student student= list.get(i);
if (student!=null&&sid.equals(student.getSid())){
index=i;
break;
}
}
return index;
}
public void deletustudent(String delid) {//方法里面带参数的要加
int index=getindex(delid);
list.remove(index);
}
//删除学生信息
/* public void deleteStudent(String delid, Student student) {
int index =getindex(delid);
list.remove(index);
}*/
}
daoTeacher类
public class daoTeacher extends daoperson {
private static ArrayList<Teacher> list=new ArrayList<>();
public static Teacher[] findteacher() {
Teacher[] tea=new Teacher[list.size()]; //用数组接受集合,并赋值给数组
for (int i = 0; i < tea.length; i++) {
tea[i]=list.get(i);
}
return tea;
}
public boolean addteacher(Teacher tea) {
list.add(tea);
return true;
}
public void updateteacher(String updatesid, Teacher newtea) {
int index=getindex(updatesid);
list.set(index,newtea);
}
public int getindex(String sid){ //遍历索引,传入学号
int index=-1;
for (int i = 0; i < list.size(); i++) {
Teacher teachers=list.get(i);
if (teachers!=null&&sid.equals(teachers.getSid())){
index=i;
break;
}
}
return index;
}
public void deleteteacher(String delsid) {
int index=getindex(delsid);
list.remove(index);
}
}
domin包下内容(定义成员变量)
person类
public class person {
private String sid;
private String name;
private int age;
private String birthday;
public person(){}
public person(String sid, String name, int age, String birthday){
this.sid=sid;
this.name=name;
this.age=age;
this.birthday=birthday;
}
public void setSid(){
this.sid=sid;
}
public String getSid(){
return sid;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return age;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getBirthday() {
return birthday;
}
}
Student类
public class Student extends person{
public Student(String sid, String name, int age, String birthday) {
super(sid, name, age, birthday);
}
}
Teacher类
public class Teacher extends person {
public Teacher(String sid, String name, int age, String birthday) {
super(sid, name, age, birthday);
}
}
service包下内容(业务员业务)
serviceStudent类
public class serviceStudent {
private static daoStudent daoStudent=new daoStudent();
public boolean addStudent(Student student){
return daoStudent.addstudent(student);
}
public boolean isExists(String sid) {//判断学号是否存在
Student[] stu=daoStudent.findAllStudent();
boolean exists = false;
for (int i = 0; i < stu.length; i++) {
Student stu1 =stu[i];
if(stu1 != null && sid.equals(stu1.getSid())){
exists = true;
break;
}
}
return exists;
}
/*public Student[] lookstudent() {
// Student[] allStudent= daoStudent.findAllStudent().toArray(new Student[0]);
//return allStudent;
}
*/
public void updatestudent(String updateid, Student newstu) {
daoStudent.updatestudent(updateid,newstu);
}
public Student[] findallStudent() {
Student[] allStudent=daoStudent.findAllStudent();
boolean flag=false;
for (int i = 0; i < allStudent.length; i++) {
Student student=allStudent[i];
if(student!= null){
flag = true;
break;
}
}
if (flag){
return allStudent;
}
return null;
}
public void deletestudent(String delid) {
daoStudent.deletustudent(delid);
}
/* ArrayList<Student> alllist =daoStudent.findAllStudent();
boolean flag = false;
for (int i = 0; i < alllist.size(); i++) {
Student stu = alllist.get(i);
if(stu != null){
flag = true;
break;
}
}
if(flag){
// 有信息
return alllist;
}else{
// 没有信息
return null;
}*/
}
serviceTeacher类
public class serviceTeacher {
private static daoTeacher daoTeacher= new daoTeacher();
public static boolean addteacher(Teacher Tea){
return daoTeacher.addteacher(Tea);
}
public static Teacher[] findteacher() {
Teacher[] allteacher=daoTeacher.findteacher(); //接收数组并判定数组;
boolean flag=false;
for (int i = 0; i < allteacher.length; i++) {
Teacher teachers=allteacher[i]; //boolean一个参数为false,遍历数组不为空为true
if (teachers!=null){
flag=true;
break;
}
}
if (flag){ //不为空true返回接收的数组, 为空false数组为null;
return allteacher;
}
return null;
}
public static boolean isExists(String sid) {
Teacher[] tea=daoTeacher.findteacher();
boolean exists = false;
for (int i = 0; i < tea.length; i++) {
Teacher tea1 =tea[i];
if(tea1!= null && sid.equals(tea1.getSid())){
exists = true;
break;
}
}
return exists;
}
public static void updateteacher(String updatesid, Teacher newtea) {
daoTeacher.updateteacher(updatesid,newtea);
}
public static void deleteteacher(String delsid) {
daoTeacher.deleteteacher(delsid);
}
}
entry包(里面是主方法main–运行类)
infomanagerentry类
public class infomanagerentry {
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
while (true) {
System.out.println("*******欢迎来到王者荣耀管理系统*******");
System.out.println("1.学生管理系统**2.老师管理系统**3.退出");
String chioce = sc.next();
switch (chioce) {
case "1":
System.out.println("学生管理系统");
controlStudent studentController = new controlStudent();
studentController.start();
break;
case "2":
System.out.println("教师管理系统");
controlTeacher controlTeacher=new controlTeacher();
controlTeacher.start();
break;
case "3":
System.out.println("退出王者系统");
System.exit(0);
}
}
}
}
实现效果
找不到代码了,就跟简化的这个一样
插入数据
查看学生
修改学生
删除学生
退出