Java图书管理系统课程设计

本文实例为大家分享了Java图书管理系统的具体代码,供大家参考,具体内容如下

大二上学期做的一个Java课程设计,总分为四个Java文件,AllBook,AllBorrow,AllStudent,Tushu。

本系统是一个面向图书馆的管理系统,具有一定的实用性。它主要完成了图书的基本操作功能,全校学生信息的相关基本操作,以及对图书的借阅归还管理。本系统采用当前流行的面向对象的JAVA语言开发工具eclipse来完成整个系统的设计。系统在设计过程中不可避免地遇到了各种各样的问题,由于整个系统完全都是由个人设计的,有关eclipse许多细节问题都要靠自己去摸索,加之本人水平有限,有很多的方面还不够完善,数据不能永久保留。希望在学习更多的知识之后能将系统做的更加完善,更加实用。

文件位置

AllBook

package tushuguan;

import java.io.Serializable;
import java.util.Scanner;

//------------------------图书信息的代码--------------------------
@SuppressWarnings("serial")
class Book implements Serializable{ //图书类
        String BookNo;              //编号
        String BookName;            //书名
        String BookAuthor;          //作者
        int zk;                              //是否在库
        int cs;                              //借阅次数
        showInfo info=new showInfo();        //借阅信息日常显示
    public Book(){                           //定义构造方法,初始化数据项
            BookNo="";
            BookName="";
            BookAuthor="";     
            zk=0;
            cs=0;
            }
        public String getBookNo(){
            return BookNo;
        }
        public String getBookName(){
            return BookName;
        }
        public String getBookAuthor(){
            return BookAuthor;
        }       
    //````````````````````````新增图书信息``````````````````````````
    public void inputBook(){                 //输入单个图书
        @SuppressWarnings({"resource" })
        Scanner in2=new Scanner(System.in);  
        System.out.print("请输入图书编号:");
        String s;
        s=in2.nextLine();
        int a;
        a=AllBook.queryBooByBookNo(s);
        while(a!=-1){                            //判断是否已有相同编号的图书存在
        System.out.print("该书籍已存在,请重新输入!\n");
        System.out.print("请输入图书编号:");
        s=in2.nextLine();
        a=AllBook.queryBooByBookNo(s);
        }
        BookNo=s;
        System.out.print("请输入图书名称:");
        BookName=in2.nextLine();
         System.out.print("请输入图书作者:");
        BookAuthor=in2.nextLine();
        zk=1;
        }          
    public void showBook(){                        //显示单个图书信息
    System.out.print("图书编号:"+BookNo+"\n图书名称:"+BookName+"\n图书作者:"+BookAuthor+"\n借阅次数:"+cs);
            if(zk==1)
                System.out.print("\n该图书:在库\n");
            else
                System.out.print("\n该图书: 不在库\n");
           }        
        }       
    @SuppressWarnings("serial")
public class AllBook  implements Serializable{      //所有图书集合类 
        static Book []Book=new Book[20];       //定义一个能存储20个图书的数组对象
        static int index=0;                                                  //用于存储当前已有图书的数量
    public  AllBook(){                     //初始化所有单元的图书信息;
        for(int i=0;i4){
                                System.out.print("该数字无效,请重新选择:");
                                n=in2.nextInt();}
                switch(n){
                case 1:{                            
                         System.out.println("请输入修改后的图书编号:");
                         Book[i].BookNo=in3.nextLine();    break;
                         }
                case 2:{
                        System.out.println("请输入修改后的图书名称:");
                        Book[i].BookName=in3.nextLine();break;
                         }
                case 3:{
                       System.out.println("请输入修改后的图书作者:");
                       Book[i].BookAuthor=in3.nextLine();break;
                         }
                case 4:{
                       System.out.println("请输入修改后的图书编号、图书名称 、图书作者:");
                       System.out.println("请输入修改后的图书编号:");
                       Book[i].BookNo=in3.nextLine();
                       System.out.println("请输入修改后的图书名称:");
                       Book[i].BookName=in3.nextLine();
                       System.out.println("请输入修改后的图书作者:");
                       Book[i].BookAuthor=in3.nextLine();
                }
                         } System.out.print("修改成功!");      
                }
                    else
                    System.out.print("该图书不存在!");
                }                          
     }  

AllBorrow

package tushuguan;

import java.io.Serializable;
import java.util.Scanner;
class showInfo {                 //定义一个借阅信息显示类
       String lendtime;            //借书日期
       String returntime;          //还书日期
       String lendStuNo;           //借书学生编号
       String lendStuName;         //借书学生姓名
       String lendStuClass;        //借书学生班级
       public showInfo(){          //定义构造方法,初始化数据项    
           lendtime="";                
           returntime="";
           lendStuNo="";
           lendStuName="";
           lendStuClass="";
       }
}
@SuppressWarnings("serial")
class Borrow implements Serializable{//借阅类
     static int BoCs;                //最大的借阅次数
     String StudentNo;
     String BookNo;
    public Borrow(){          //定义构造方法,初始化数据项            
             BoCs=0;
             StudentNo="";
             BookNo="";
            }
}
@SuppressWarnings("serial")
class AllBorrow  implements Serializable{//所有借阅类
        
    //-----------------显示借阅信息---------------     
    public void showlendInfo(String BookNo){
          int a=AllBook.queryBooByBookNo(BookNo);      //找到该编号对应的图书下标赋值给a
          System.out.print("\n该图书的借阅信息为:");         
          System.out.print("\n该借书学生学号为:"+AllBook.Book[a].info.lendStuNo);
          System.out.print("\n该借书学生姓名为:"+AllBook.Book[a].info.lendStuName);
          System.out.print("\n该借书学生班级为:"+AllBook.Book[a].info.lendStuClass);
          System.out.print("\n该图书的借出日期:"+AllBook.Book[a].info.lendtime);
         
     }
    //---------------显示归还信息------------------
    public void showlendReturn(String BookNo){
          int a=AllBook.queryBooByBookNo(BookNo);      //找到该编号对应的图书下标赋值给a
          System.out.print("\n该图书的归还信息为:");         
          System.out.print("\n该借书学生学号为:"+AllBook.Book[a].info.lendStuNo);
          System.out.print("\n该借书学生姓名为:"+AllBook.Book[a].info.lendStuName);
          System.out.print("\n该借书学生班级为:"+AllBook.Book[a].info.lendStuClass);
          System.out.print("\n该图书的借出日期:"+AllBook.Book[a].info.lendtime);
          System.out.print("\n该图书的归还日期:"+AllBook.Book[a].info.returntime);
     }
    //----------------------多本图书借阅----------------    
    @SuppressWarnings("resource")
    public void Alllend(){
         Scanner in1=new  Scanner(System.in);
         Scanner in2=new Scanner(System.in);
         int a=0,b=0;
         String StudentNo,BookNo,d;
         int c=1;
         System.out.print("请输入你的学号:");
            StudentNo=in1.nextLine();          
            b=AllStudent.queryStuByStudentNo(StudentNo);
            if(b!=-1){                 //判断该学生是否存在
                       System.out.print("登录成功!\n");
                       while(c==1){
                         System.out.print("请查询要借阅的图书\n");            
                         System.out.print("请输入该书编号:");        
                         BookNo=in1.nextLine();
                         a=AllBook.queryBooByBookNo(BookNo);
                         if(a!=-1){   //判断图书是否存在
                          if(AllBook.Book[a].zk==1){        //判断图书是否在库     
                          AllBook.Book[a].showBook();    
                          System.out.print("\n该图书在库,请填写借阅信息:");
                          AllBook.Book[a].zk=0;      //借出图书,将图书的在库信息修改为不在库
                          AllBook.Book[a].cs++;      //借出图书,该图书借阅次数加一
                          AllBook.Book[a].info.lendStuNo=AllStudent.Student[b].StudentNo;
                          AllBook.Book[a].info.lendStuName=AllStudent.Student[b].StudentName;
                          AllBook.Book[a].info.lendStuClass=AllStudent.Student[b].StudentClass;
                          System.out.print("\n请填写借出日期(xxxxxxxx):");
                          d=in1.nextLine();
                          while(d.length()!=8){     //判断日期格式是否正确
                              System.out.print("日期格式错误,请重新输入8个字符的借书日期(如20180101)");
                              System.out.print("\n请重新填写归还日期:");
                              d=in1.nextLine();
                        }
                         AllBook.Book[a].info.lendtime=d;
                         System.out.print("借阅成功!");
                         
                          }
                          else
                             System.out.print("图书不在库,借阅失败!");
                         }
                         else
                              System.out.print("图书不存在,借阅失败!");
                                      
                    System.out.print("\n是否继续借阅:1-是,0-否");          
                    c=in2.nextInt();
                    switch(c){
                        case 0: c=0;break;
                       default: break;
                               }
                 }
            }
            else
              System.out.print("该学生信息不存在!\n");      
            }     
    //---------------归还图书管理(单本)---------
    @SuppressWarnings("resource")
    public void returnBook(){
         Scanner in1=new Scanner(System.in);
         Scanner in2=new Scanner(System.in);
         System.out.print("请输入归还图书的编号:");
         String BookNo,b;
         BookNo=in1.nextLine();
         int a=AllBook.queryBooByBookNo(BookNo);
         if(a!=-1){
          if(AllBook.Book[a].zk==0){            
              System.out.print("\n请填写归还日期(xxxxxxxx):");
             b=in2.nextLine();
            if(b.length()!=8){   //判断日期格式
             while (b.length()!=8){        
                  System.out.print("归还日期出错!"); 
                  System.out.print("\n请重新填写归还日期,例如20180101:");
                  AllBook.Book[a].info.returntime=in2.nextLine();
            }}        
            else
              while(AllBook.Book[a].info.returntime.compareTo(AllBook.Book[a].info.lendtime)<=0){
              System.out.print("归还时间不对,请输入不小于借阅日期的日期");
              System.out.print("\n请重新填写归还日期:");
              AllBook.Book[a].info.returntime=in2.nextLine();
            }
            AllBook.Book[a].zk=1;
              System.out.print("归还成功!"); 
              showlendReturn(BookNo);}
          else
              System.out.print("该图书在库不需要归还!");
         }
         else
             System.out.print("不存在该图书!");         
     }      
      //--------------------多本图书归还-------------------
    @SuppressWarnings("resource")
    public void Allreturn(){
     int c=1;
     Scanner in1=new  Scanner(System.in);     
     while(c==1){
            returnBook(); 
            System.out.print("\n\n是否继续归还:1-是,0-否");          
            c=in1.nextInt();
            switch(c){
             case 0: c=0;break;
             case 1: break;
            default: break;
                    }
             }     
     }
    
    //----------------按借阅次数查询-------------------
    public int  findBoCs(){  //找到最大的借阅次数
     for(int i=0;i 
 

AllStudent

package tushuguan;

import java.io.Serializable;
import java.util.Scanner;
    @SuppressWarnings("serial")
class Student implements Serializable{ //学生类
           String StudentNo;    //学号
           String StudentName;  //书名
           String StudentClass; //班级
                
    public Student(){//定义构造方法,初始化数据项
               StudentNo="";
               StudentName="";
               StudentClass="";         
               }
           public String getStudentNo(){
               return StudentNo;
           }
           public String getStudentName(){
               return StudentName;
           }
           public String getStudentClass(){
               return StudentClass;
           }          
           //````````````````````````新增学生信息``````````````````````````
       public void inputStudent(){//输入单个学生
               @SuppressWarnings("resource")
            Scanner in2=new Scanner(System.in);
               System.out.print("请输入学生学号:");
               String s;
               s=in2.nextLine();
               int a;
            a=AllStudent.queryStuByStudentNo(s);
            while(a!=-1){         //判断是否已经存在该学号的学生
             System.out.print("该学生已存在,请重新输入!\n");
             System.out.print("请输入学生学号:");
             s=in2.nextLine();
             a=AllStudent.queryStuByStudentNo(s);
            }
            StudentNo=s;
               System.out.print("请输入学生名称:");
               StudentName=in2.nextLine();
               System.out.print("请输入学生班级:");
               StudentClass=in2.nextLine();              
           }

    public void showStudent(){//显示单个学生信息
               System.out.print("学生学号:"+StudentNo+"\n学生名称:"+StudentName+"\n学生班级:"+StudentClass);
       
           }        
       }       
    @SuppressWarnings("serial")
public class AllStudent implements Serializable{                      //所有学生集合类 
           static Student []Student=new Student[20];                     //定义一个能存储20个学生的数组对象
           static int index=0;                                                  //用于存储当前已有学生的数量
           public  AllStudent(){                                        //初始化所有单元的学生信息;
            for(int i=0;i4){
                              System.out.print("该数字无效,请重新选择:");
                              n=in2.nextInt();}
                           switch(n){
                  case 1:{                              
                          System.out.println("请输入修改后的学生学号:");
                          Student[i].StudentNo=in3.nextLine();    break;
                           }
                  case 2:{
                          System.out.println("请输入修改后的学生姓名:");
                          Student[i].StudentName=in3.nextLine();break;
                           }
                  case 3:{
                          System.out.println("请输入修改后的学生班级:");
                          Student[i].StudentClass=in3.nextLine();break;
                              }
                  case 4:{
                          System.out.println("请输入修改后的学生学号、姓名、班级:");
                          System.out.println("请输入修改后的学生学号:");
                          Student[i].StudentNo=in3.nextLine();
                          System.out.println("请输入修改后的学生姓名:");
                        Student[i].StudentName=in3.nextLine();
                        System.out.println("请输入修改后的学生班级:");
                          Student[i].StudentClass=in3.nextLine();
                  }
                           } System.out.print("修改成功!");      
                  }
                      else
                      System.out.print("该学生不存在!");
                  }                            
    }

Tushu

package tushuguan;

import java.io.Serializable;
import java.util.Scanner;    
    @SuppressWarnings("unused")
class Menu{//菜单类
        AllBook Book=new AllBook();
        AllStudent Student=new AllStudent();
        AllBorrow Borrow= new AllBorrow(); 
        
        public void showMenu(){//主菜单部分
               System.out.println("******系部图书成绩管理系统*******");
               System.out.println("**     1.图书信息管理                   **");
               System.out.println("**     2.学生信息管理                   **");
               System.out.println("**     3.借阅信息管理                   **");
               System.out.println("**     0.退出总管理系统                **");
               System.out.println("***************************");
               System.out.println("请选择: ");
               selectMenu();
           }
           public void selectMenu(){//选择主菜单部分
               @SuppressWarnings("resource")
            Scanner in1=new Scanner(System.in);
               int a;
               a=in1.nextInt();
               while(a<0||a>3){
                   System.out.print("该数字无效,请重新选择:");
                   a=in1.nextInt();
               }
               switch (a){
               case 1:{showMBook();break;}
               case 2:{showMStudent();break;}
               case 3:{showMBorrow();break;}
             case 0:{System.out.print("******感谢您的使用!******");}
               }
           }     
      //-------------------------图书信息管理目录----------------------------- 
           public void showMBook(){//图书信息管理目录     
               System.out.println("\n*******图书信息管理目录******");
               System.out.println("**       1.新增                            **");
               System.out.println("**       2.查询                            **");
               System.out.println("**       3.删除                            **");
              System.out.println("**       4.浏览                            **");
              System.out.println("**       5.修改                            **");
               System.out.println("**       6.返回上一菜单              **");
               System.out.println("**       0.退出总管理系统          **");
               System.out.println("************************************");
               System.out.println("请选择:");
               selectMBook();
           }
           public void selectMBook(){//选择图书目录
               @SuppressWarnings("resource")
            Scanner in1=new Scanner(System.in);
               int b;
               b=in1.nextInt();
               while(b>6||b<0){
                   System.out.print("该数字无效,请重新选择:");
                   b=in1.nextInt();
               }
               switch (b){
               case 1:{
                                   Book.inputAB();                  //新增图书信息
                                   System.out.print("\n完成图书信息新增操作.\n");
                                   showMBook();break;}
               case 2:{                                            
                                  
                                findBook();                 //查找图书信息
                                   System.out.print("\n完成图书信息查询操作.\n");
                                   showMBook();break;}
           
               case 3:{                                             
                                  Book.deleteByBookNo();           //删除图书信息
                                  System.out.print("\n完成图书信息删除操作.\n");
                                  showMBook();break;}
               case 4:{                                              
                                  Book.showAllBook();              //浏览图书信息                                   
                                  System.out.print("\n完成图书信息浏览操作.\n");
                                  showMBook();break;}
               case 5:{                                             
                                  Book.reviseByBookNo();        //修改图书信息
                                  System.out.print("\n完成图书信息修改操作.\n");
                                  showMBook();break;}
               case 6:{                                            
                                  showMenu();}                         //返回上一界面
               
               case 0:{           System.out.print("\n******感谢您的使用!******");System.exit(0);}      
           }       
       }
      //`````````````````````````查询图书信息````````````````````````
        public void findBook(){
               System.out.print("\n请选择查找图书方式:\n");
               System.out.println("*******查找图书方式******");
               System.out.println("**       1.按图书编号查找                 **");
               System.out.println("**       2.按图书名称查找                 **");
               System.out.println("**       3.按图书作者查找                 **");
               System.out.println("**       0.返回上一菜单                     **");
               @SuppressWarnings("resource")
              Scanner in2=new Scanner(System.in);
                       int c;
                      c=in2.nextInt();
                      while(c<0||c>3){
                             System.out.print("该数字无效,请重新选择:");
                             c=in2.nextInt();}
                      switch(c){
                      case 1:{
                          Book.queryByBookNo();break;        //按编号查询图书信息
                                     }
                      case 2:{
                          Book.queryByBookName(); break;     //按书名查询图书信息
                                    }
                      case 3:{
                          Book.queryByBookAuthor(); break;   //按作者查询图书信息
                                     }
                      case 0:{   
                             showMBook();}}
            }
      //-------------------------学生信息管理目录-----------------------------
        public void showMStudent(){//学生信息管理目录       
           System.out.println("\n*******学生信息管理目录******");
           System.out.println("**       1.新增                        **");
           System.out.println("**       2.查询                        **");
           System.out.println("**       3.删除                        **");
          System.out.println("**       4.浏览                        **");
          System.out.println("**       5.修改                        **");
           System.out.println("**       6.返回上一菜单          **");
           System.out.println("**       0.退出总管理系统       **");
           System.out.println("*************************");
           System.out.println("请选择:");
           selectMStudent();
       }
         public void selectMStudent(){//选择学生目录
           @SuppressWarnings("resource")
        Scanner in1=new Scanner(System.in);
           int b;
           b=in1.nextInt();     
           while(b<0||b>6){
               System.out.print("该数字无效,请重新选择:");
               b=in1.nextInt();
           }
           switch (b){
           case 1:{
                             Student.inputAS();               //新增学生信息
                             System.out.print("\n完成学生信息新增操作\n");
                             showMStudent();break;}
           case 2:{
                             findStudent();           //查找学生信息
                             System.out.print("\n完成学生信息查询操作\n");
                             showMStudent();break;}
       
           case 3:{                                                                                       
                             Student.deleteByStudentNo();       //删除学生信息                                                 
                             System.out.print("\n完成学生信息删除操作\n");
                             showMStudent();break;}
           case 4:{
                             Student.showAllStudent();     //浏览学生信息                                           
                             System.out.print("\n完成学生信息浏览操作\n");
                             showMStudent();break;}
           case 5:{                                                                                                    
                             Student.reviseByStudentNo();//修改图书信息
                             System.out.print("\n完成学生信息修改操作\n");
                          showMStudent();break;}
           case 6:{
                             showMenu();    }                      //返回主菜单
           
           case 0:{          System.out.print("\n******感谢您的使用!******");System.exit(0);}
       
       }      
   }
        //`````````````````````````查询学生信息````````````````````````
           @SuppressWarnings("resource")
    public void findStudent(){
                  System.out.print("\n请选择查找学生方式:\n");
               System.out.println("***********查找学生方式**********");
               System.out.println("**       1.按学生学号查找                 **");
               System.out.println("**       2.按学生名称查找                 **");
               System.out.println("**       3.按学生班级查找                 **");
               System.out.println("**       0.返回上一菜单                      **");
               Scanner in2=new Scanner(System.in);
               int c;
               c=in2.nextInt();
               while(c<0||c>3){
                   System.out.print("该数字无效,请重新选择:");
                   c=in2.nextInt();}
      switch(c){
                  case 1:{
                        Student.queryByStudentNo();break;      //按学号查询学生信息
                                    }
                  case 2:{
                        Student.queryByStudentName(); break;   //按姓名查询学生信息
                                   }
                  case 3:{
                       Student.queryByStudentClass(); break;   //按班级查询学生信息
                                   }
                  case 0:{ showMStudent();}
               }                   
           }
      //-------------------------图书借阅信息管理目录-----------------------------
        public void showMBorrow(){
        System.out.println("\n*******借阅图书信息管理目录*****");
        System.out.println("**       1.图书借阅管理                **");
        System.out.println("**       2.图书归还管理                **");        
           System.out.println("**       3.图书查询管理                **");
           System.out.println("**       4.统计查询管理                **");        
           System.out.println("**       5.返回上一菜单                **");
           System.out.println("**       0.退出总管理系统             **");
           System.out.println("**********************************");
           System.out.println("请选择:");
           selectMBorrow();
       }
        public void selectMBorrow(){//选择图书目录
           @SuppressWarnings("resource")
        Scanner in1=new Scanner(System.in);
           int b;
           b=in1.nextInt();
           while(b<0||b>5){
               System.out.print("该数字无效,请重新选择:");
               b=in1.nextInt();}
           switch(b){
           case 1:{ 
                   Borrow.Alllend();          //图书借阅管理
                   System.out.print("\n完成图书借阅操作\n");
                showMBorrow();break;                            
           }
           case 2:{
                   Borrow.Allreturn();       //图书归还管理
                System.out.print("\n完成图书借阅操作\n");
                showMBorrow();break;      
           }          
           case 3:{
                   Borrow.findbook();       //图书查询管理
                   System.out.print("\n完成图书查询操作\n");
                showMBorrow();break;  
           }
           case 4:{
               TjfindBook();     //统计查询管理
               System.out.print("\n完成图书统计查询操作\n");
               showMBorrow();break;      
        }
           case 5:{   showMenu();      }     //返回主菜单
           case 0:{   System.out.print("\n******感谢您的使用!******");System.exit(0);}          
           }
        }
    //-------------------统计查询管理--------------------------
    public void TjfindBook(){
     System.out.println("请选择统计查询的方式:\n");
     System.out.println("1-按借阅次数查询");
     System.out.println("2-按在库与否查询");
     System.out.println("0-返回上一菜单  ");
     @SuppressWarnings("resource")     
     Scanner in1 =new Scanner(System.in);
     int a;
     a=in1.nextInt();
     while(a<0||a>3){
            System.out.print("该数字无效,请重新选择:");
            a=in1.nextInt();}
     switch(a){
     case 1:{
                   Borrow.findByTj();      //按借阅次数查询
                   System.out.print("\n完成统计查询图书操作\n");
                   showMBorrow();break;
                                 }
     case 2:{
                   findByzk();            //按是否在库查询
                   System.out.print("\n完成统计查询图书操作\n");
                   showMBorrow();break;
                                  }
     case 0:{      showMBorrow();}  //返回上一菜单
     }}
    //--------------按是否在库查询图书----------------------
    public void findByzk(){
             System.out.print("请选择在库模式查询:\n");
             System.out.println("1-显示所有在库图书");
             System.out.println("2-显示所有不在库图书");
             System.out.println("0-返回上一菜单");      
             @SuppressWarnings("resource")
             Scanner in1 =new Scanner(System.in);
             int a;
             a=in1.nextInt();
             while(a<0||a>3){
                    System.out.print("该数字无效,请重新选择:");
                    a=in1.nextInt();}
             switch(a){
             case 1:{
                  Borrow.showzkBook();break;  //显示所有在库图书
             }
             case 2:{
                  Borrow.showbzkBook();break;  //显示所有不在库图书
             }
             case 0:{ showMBorrow();}
             }
        }
}
public class Tushu{
    public static void main(String []args){
        Menu menu =new Menu();
        menu.showMenu();
    }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

你可能感兴趣的:(Java图书管理系统课程设计)