当前位置 : 主页 > 编程语言 > c++ >

简单的学生管理系统

来源:互联网 收集:自由互联 发布时间:2021-06-30
Demo.java package org.jxnd.com;public class Demo {public static void main(String[] args) {Manager info=new Manager();info.menu();}} Friend.java package org.jxnd.com;import java.io.Serializable;public class Friend implements Serializable{pub
Demo.java
package org.jxnd.com;

public class Demo {
	public static void main(String[] args) {
		Manager info=new Manager();
		info.menu();
	}
}
Friend.java
package org.jxnd.com;

import java.io.Serializable;

public class Friend implements Serializable{
	public int mid;
	public int fid;
	public String name;
	public Friend() {
		super();
		// TODO 自动生成的构造函数存根
	}
	public Friend(int mid, int fid, String name) {
		super();
		this.mid = mid;
		this.fid = fid;
		this.name = name;
	}
	@Override
	public String toString() {
		return "Friend [mid=" + mid + ", fid=" + fid + ", name=" + name + "]";
	}
	
	
	
}
//1001	1002	马屁飞
//1001	1003	美女丽
//1003	1002	小飞飞
//1003	10001	热巴
Manager.java
package org.jxnd.com;

import java.util.ArrayList;

//总管理类
public class Manager {
	public static ArrayList
 
   sList=new ArrayList
  
   (); public static ArrayList
   
     tList=new ArrayList
    
     (); public static String sPath="stu.bin"; static{ tList.add(new Teacher("admin","123456")); sList.add(new Student("大司马", "123456", 1001, "男", "0808008", "安徽-芜湖")); sList.add(new Student("马飞飞", "123456", 1002, "男", "0808008", "安徽-芜湖")); sList.add(new Student("张飞丽", "123456", 1003, "男", "0808008", "安徽-芜湖")); } public void menu(){ if(Tools.loadObject(Manager.sPath)!=null) Manager.sList=(ArrayList
     
      ) Tools.loadObject(Manager.sPath); if(Tools.loadObject(StudentManager.fPath)!=null) StudentManager.fList=(ArrayList
      
       ) Tools.loadObject(StudentManager.fPath); while (true) { switch (Tools.menuFactory("学生登录,老师登录")) { case 1: StudentManager info1=new StudentManager(); info1.login(); break; case 2: TeacherManager info2=new TeacherManager(); info2.login(); break; default: break; } } } }
      
     
    
   
  
 
Tools.java
package org.jxnd.com;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Scanner;

public class Tools{
	//静态资源和非静态资源的区别?
	static Scanner input=new Scanner(System.in);
	public static String getString(String msg){
		p(msg);
		return input.next();
	}
	
	//加载信息
	public static Object loadObject(String pathName){
		Object obj=null;
		if(!new File(pathName).exists()) //判断这个文件是否存在
			return obj;
		try {
			ObjectInputStream input=new ObjectInputStream(new FileInputStream(pathName));
			obj=input.readObject();
			input.close();
			return obj;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	//保存信息
	public static boolean saveObject(Object obj,String pathName){
		try {
			ObjectOutputStream output=new ObjectOutputStream(new FileOutputStream(pathName));
			output.writeObject(obj);
			output.close();
			return true;
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
	}

	//获取用户输入的整形
	public static int getInt(String msg){
		p(msg);
		return input.nextInt();
	}

	public static boolean isContinue(String msg){
		if(getString(msg).equalsIgnoreCase("y"))
			return true;
		return false;
	}

	public static void pl(String msg){
		System.out.println(msg);
	}


	public static void pl(Object obj){
		System.out.println(obj);
	}

	public static void p(String msg){
		System.out.print(msg);
	}
	
	//菜单生成器
	public static int menuFactory(String msg){
		String[] strs=msg.split(",");
		
		StringBuffer sb=new StringBuffer();
		sb.append("--------------------------------------\n");
		for (int i=0;i
 
  :");
		return getInt(sb.toString());
	}
}
 
Person.java
package org.jxnd.com;

import java.io.Serializable;

public class Person implements Serializable{
	private String name;
	private String pwd;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
	public Person(String name, String pwd) {
		super();
		this.name = name;
		this.pwd = pwd;
	}
	public Person() {
		super();
	}
	@Override
	public boolean equals(Object arg0) {
		Person info=(Person)arg0;
		if(info.name.equals(this.name)&&info.pwd.equals(this.pwd))
				return true;
		return false;
	}
	
	
}
网友评论