自寫的java學生資訊管理系統
import com.czh.myInterface.AdminInterface;
/**
* 管理員類的資訊
* @author GuCe
*2016年3月31日16:42:16
*/
public abstract class Admin implements AdminInterface{
public String adminName;//管理員姓名
public int age;//年齡
public String sex;//性別
public String getAdminName() {
return adminName;
}
public void setAdminName(String adminName) {
this.adminName = adminName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
package com.czh.son;
import java.util.ArrayList;
import java.util.Scanner;
import com.czh.Person.Student;
import com.czh.Person.Teacher;
import com.czh.son.XueSheng;
import com.czh.Person.Admin;
/**
* 這是管理員操作的系統方法
* @author GuCe
*2016年3月31日16:59:25
*/
public class GuanLiYuan extends Admin{
@Override
public void method() {
// TODO Auto-generated method stub
System.out.println("請輸入操作:0是查詢學生資訊,1是新增學生資訊,2是修改學生資訊,3是刪除學生資訊,"
+ "\n4是查詢教師資訊,5是新增教師資訊,6是修改教師資訊,7是查詢學生成績,8是統計學生成績,back是返回");
Scanner input =new Scanner(System.in);
String studentName=input.next();
if("0".equals(studentName)){
System.out.println("歡迎進入學生資訊查詢介面,\n1是查詢姓名,\nback是返回上一次");
Scanner input1 =new Scanner(System.in);
String xueSheng=input1.next();
if("1".equals(xueSheng)){
System.out.println("請輸入您要查詢姓名的學號");
Student stud=new XueSheng();
Scanner newInputID =new Scanner(System.in);
String studentID = newInputID.next();
stud.setId(Integer.parseInt(studentID));
ArrayList<Student> studentList = XueSheng.run();
for(int i=0;i<studentList.size(); ++i)
{
Student stu = studentList.get(i);
int tempID = Integer.parseInt(studentID);
if (tempID == stu.getId())
{
System.out.println("您的學號對應的姓名是:"+stu.getStudentName());
method();
}
}
}
if("back".equals(xueSheng)){
method();
}
}
if("1".equals(studentName)){
System.out.println("已進入新增學生資訊介面,1是新增姓名,學號,班級,back是返回上一級");
Scanner input0=new Scanner(System.in);
String student0=input0.next();
if("1".equals(student0)){
System.out.println("您可以新增姓名了");
}else if("back".equals(student0)){
method();
}
Student stud=new XueSheng();
System.out.println("請輸入姓名:");
Scanner newInput =new Scanner(System.in);
String studentName2 = newInput.next();
stud.setStudentName(studentName2);
System.out.println("請輸入學號:");
Scanner newInputID =new Scanner(System.in);
String studentID = newInputID.next();
stud.setId(Integer.parseInt(studentID));
ArrayList<Student> studentList1 = XueSheng.run();
for(int i=0;i<studentList1.size(); ++i)
{
Student stu = studentList1.get(i);
int tempID = Integer.parseInt(studentID);
if (tempID == stu.getId())
{
System.out.println("已存在學號"+studentID);
method();
}
}
System.out.println("請輸入年齡:");
Scanner newInputAge =new Scanner(System.in);
String studentAge = newInputAge.next();
stud.setAge(Integer.parseInt(studentAge));
System.out.println("插入學號"+studentID+"\n姓名:"+ studentName2+ "\n年齡:"+studentAge+"成功!");
Student student4=new XueSheng();
student4.setStudentName(studentName2);
student4.setId(Integer.parseInt(studentID));
student4.setAge(Integer.parseInt(studentAge));
ArrayList<Student>studentList= XueSheng.run();
studentList.add(student4);
method();
}
if("2".equals(studentName)){
System.out.println("已進入修改學生資訊介面,請輸入要修改學生的學號");
Student stud=new XueSheng();
Scanner newInputID =new Scanner(System.in);
String studentID = newInputID.next();
stud.setId(Integer.parseInt(studentID));
ArrayList<Student> studentList = XueSheng.run();
for(int i=0;i<studentList.size(); ++i)
{
Student stu = studentList.get(i);
int tempID = Integer.parseInt(studentID);
if (tempID == stu.getId())
{
System.out.println("學號正確,您原來的姓名是:"+stu.getStudentName()+"\n請輸入您要修改的姓名");
Scanner newInput =new Scanner(System.in);
String studentName2 = newInput.next();
stud.setStudentName(studentName2);
studentList.get(i).setStudentName(studentName2);
System.out.println("修改成功,您的姓名已經變成:"+studentName2);
}
}
method();
}
if("3".equals(studentName)){
System.out.println("已進入刪除學生資訊介面,1是刪除學生或教師,back返回");
Scanner input01 =new Scanner(System.in);
String del01 = input01.next();
if("1".equals(del01)){
System.out.println("已進入刪除介面,請輸入要刪除的學號");
Student stud=new XueSheng();
Scanner newInputID =new Scanner(System.in);
String studentID = newInputID.next();
stud.setId(Integer.parseInt(studentID));
System.out.println("請輸入要刪除的姓名");
Scanner newInputName =new Scanner(System.in);
String studentName0 = newInputName.next();
stud.setStudentName(studentName0);
ArrayList<Student> studentList1 = XueSheng.run();
for(int i=0;i<studentList1.size(); ++i)
{
Student stu = studentList1.get(i);
int tempID = Integer.parseInt(studentID);
if (tempID == stu.getId()||studentName0.equals(stu.getStudentName()))
{
Student student4=new XueSheng();
student4.setStudentName(studentName0);
student4.setId(Integer.parseInt(studentID));
ArrayList<Student> studentList= XueSheng.run();
studentList.remove(student4);
System.out.println("學號正確,您已經刪除的學生:"+stu.getStudentName());
break;
}
}
}
if("back".equals(del01)){
method();
}
method();
}
if("4".equals(studentName)){
System.out.println("已進入教師查詢介面,1是查詢姓名,back是返回");
Scanner input3 =new Scanner (System.in);
String chaXun=input3.next();
if("1".equals(chaXun)){
System.out.println("請輸入您查詢教師的工號");
Teacher tea=new JiaoShi();
Scanner teaId=new Scanner (System.in);
String teId=teaId.next();
tea.setId(Integer.parseInt(teId));
ArrayList<Teacher> teacherList=JiaoShi.fun();
for(int i=0;i<teacherList.size();++i){
Teacher teac = teacherList.get(i);
int tempID=Integer.parseInt(teId);
if (tempID == teac.getId())
{
System.out.println("您的工號對應的姓名是:"+teac.getTeacherName());
method();
}
}
}
method();
}
if("5".equals(studentName)){
System.out.println("已進入新增教師資訊介面,1是新增教師");
Scanner input1=new Scanner (System.in);
String del=input1.next();
if("1".equals(del)){
System.out.println("請輸入您要新增的教師的工號");
Teacher tea=new JiaoShi();
System.out.println("請輸入姓名:");
Scanner inputName=new Scanner(System.in);
String teacherName1=inputName.next();
tea.setTeacherName(teacherName1);
System.out.println("請輸入工號");
Scanner inputId=new Scanner(System.in);
String teacherId1=inputId.next();
tea.setId(Integer.parseInt(teacherId1));
ArrayList<Teacher>teacherList1=JiaoShi.fun();
for(int i=0;i<teacherList1.size();++i){
Teacher teac = teacherList1.get(i);
int tempID=Integer.parseInt(teacherId1);
if (tempID == teac.getId())
{
System.out.println("已存在此工號");
method();
}
}
System.out.println("插入"+teacherName1+teacherId1+"成功");
Teacher jiaoShi4=new JiaoShi();
jiaoShi4.setTeacherName(teacherName1);
jiaoShi4.setId(Integer.parseInt(teacherId1));
ArrayList<Teacher>teacherList= JiaoShi.fun();
teacherList.add(jiaoShi4);
}
method();
}
if("6".equals(studentName)){
System.out.println("已進入修改教師資訊介面,1是修改教師資訊");
Scanner input0=new Scanner(System.in);
String input1=input0.next();
if("1".equals(input1)){
System.out.println("請輸入您要修改教師的姓名");
Teacher tea=new JiaoShi();
Scanner inputName1=new Scanner(System.in);
String teacherName1=inputName1.next();
tea.setTeacherName(teacherName1);
System.out.println("請輸入您要修改教師的工號");
Scanner inputID=new Scanner(System.in);
String teacherId=inputID.next();
tea.setId(Integer.parseInt(teacherId));
ArrayList<Teacher>teacherList=JiaoShi.fun();
for(int i=0;i<teacherList.size();++i){
int tempId=Integer.parseInt(teacherId);
Teacher teac= teacherList.get(i);
if(tempId==teac.getId()){
System.out.println("您輸入正確,此時您的工號對應的姓名為:"+teac.getTeacherName()+"\n請輸入您要修改的姓名");
Scanner iput=new Scanner(System.in);
String teacherName2=iput.next();
tea.setTeacherName(teacherName2);
teacherList.get(i).setTeacherName(teacherName2);
System.out.println("您的姓名已變成:"+teacherName2);
}
}
}
method();
}
}
@Override
public void inputInformation() {
// TODO Auto-generated method stub
}
@Override
public void queryInformation() {
// TODO Auto-generated method stub
}
}
package com.czh.Person;
/**
* 學生類的資訊
* @author GuCe
*2016年3月31日16:33:43
*/
public abstract class Student {
public String studentName;//學生姓名
public String achievement;//成績
public int id;//學號
public int age;//年齡
public String revert;//返回
public String getRevert() {
return revert;
}
public void setRevert(String revert) {
this.revert = revert;
}
public String sex;//性別
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getAchievement() {
return achievement;
}
public void setAchievement(String achievement) {
this.achievement = achievement;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
@Override
public boolean equals(Object obj){
if(obj instanceof Student){
Student student =(Student)obj;
if(this.studentName.equals(student.getStudentName())&&this.id==student.getId()){
return true;
}else{
return false;
}
}
return super.equals(obj);
}
@Override
public String toString(){
return (" 學生姓名:"+studentName+" 學號:"+id+" 年齡:"+age+" 性別:"+sex);
}
@Override
public int hashCode(){
return studentName.hashCode()+id;
}
public void xueSheng3() {
// TODO Auto-generated method stub
}
}
package com.czh.son;
import java.util.ArrayList;
import java.util.Scanner;
import com.czh.Person.Student;
public class XueSheng extends Student{
static ArrayList<Student> studentList=new ArrayList<Student>();
public String xueSheng;
public String getXueSheng(){
return xueSheng;
}
public void setXueSheng(String xueSheng){
this.xueSheng =xueSheng;
}
public String xueSheng1;
public String getXueSheng1(){
return xueSheng1;
}
public void setXueSheng1(String xueSheng1){
this.xueSheng1 =xueSheng1;
}
public int xueSheng2;
public int getXueSheng2(){
return xueSheng2;
}
public void setXueSheng2(int xueSheng2){
this. xueSheng2=xueSheng2;
}
public static ArrayList<Student> run(){
Student student=new XueSheng();
student.setStudentName("小白");
student.setId(01);
student.setAge(21);
Student student1=new XueSheng();
student1.setStudentName("小王");
student1.setId(02);
student1.setAge(21);
Student student2=new XueSheng();
student2.setStudentName("秋葉依劍");
student2.setId(03);
student2.setAge(20);
Student student3=new XueSheng();
student3.setStudentName("初一");
student3.setId(04);
student3.setAge(20);
studentList.add(student);
studentList.add(student1);
studentList.add(student2);
studentList.add(student3);
for(int i=0;i<studentList.size();++i){
String tempStudentName=studentList.get(i).getStudentName();
int tempId=studentList.get(i).getId();
int tempAge=studentList.get(i).getAge();
}
return studentList;
}
}
package com.czh.Person;
/**
* 教師類的資訊
* @author GuCe
*2016年3月31日16:38:42
*/
public abstract class Teacher {
public String teacherName;//教師姓名
public int id;//年齡
public String sex;//性別
public String getTeacherName() {
return teacherName;
}
public void setTeacherName(String teacherName) {
this.teacherName = teacherName;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
package com.czh.son;
import java.util.ArrayList;
import com.czh.Person.Teacher;
public class JiaoShi extends Teacher{
static ArrayList<Teacher> teacherList=new ArrayList<Teacher>();
public static ArrayList<Teacher> fun(){
Teacher jiaoShi=new JiaoShi();
jiaoShi.setTeacherName("張老師");
jiaoShi.setId(101);
Teacher jiaoShi1=new JiaoShi();
jiaoShi1.setTeacherName("鞠老師");
jiaoShi1.setId(102);
Teacher jiaoShi2=new JiaoShi();
jiaoShi2.setTeacherName("於老師");
jiaoShi2.setId(103);
teacherList.add(jiaoShi);
teacherList.add(jiaoShi1);
teacherList.add(jiaoShi2);
for(int i=0;i<teacherList.size();++i){
String tempStudentName1=teacherList.get(i).getTeacherName();
int tempId1=teacherList.get(i).getId();
}
return teacherList;
}
}
package com.czh.myInterface;
/**
* 連結管理員父類與子類之間的橋樑。
* @author GuCe
*2016年3月31日17:00:45
*/
public interface AdminInterface {
public abstract void method();//管理員操作的一個總的概覽
public abstract void inputInformation();//錄入資訊
public abstract void queryInformation();//查詢資訊
}
package com.czh.myInterface;
public interface StudentInterface {
}
package com.czh.myInterface;
public interface TeacherInterface {
}
package com.czh.main;
import com.czh.son.GuanLiYuan;
public class Main {
public static void main(String[] args){
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("歡迎進入學生管理系統!\n Welcome to the student information management system!");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
GuanLiYuan guanliyuan=new GuanLiYuan();
guanliyuan.method();
}
}