温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何用Java代码实现图书管理系统

发布时间:2022-02-25 13:53:35 来源:亿速云 阅读:134 作者:iii 栏目:开发技术

这篇文章主要介绍“如何用Java代码实现图书管理系统”,在日常操作中,相信很多人在如何用Java代码实现图书管理系统问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何用Java代码实现图书管理系统”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

文件位置

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;i<Book.length;i++){
            Book[i]=new Book();
            }
    }
    //---------------输入多个图书信息--------------------
    public void inputAB(){                      
        int a=1;
        for(int i=index;i<Book.length;i++){
            if(a==1){
             System.out.print("下面录入第"+(index+1)+"本图书的信息:\n");
            Book[index].inputBook();
             index++;
             System.out.print("继续添加请按1,停止添加请按0:");
                int b;
                @SuppressWarnings("resource")
             Scanner in1=new Scanner(System.in);
                b=in1.nextInt();
               switch(b){
               case 0: a=0;break;
               default: break;
                        }
                    }
         }                
    }      
    //`````````````````````````浏览多个图书信息````````````````````````
    public void showAllBook(){//显示所有图书信息
        System.out.print("共有"+index+"本书");
            for(int i=0;i<index;i++){
                System.out.print("\n下面输出第"+(i+1)+"本书的信息:\n");
            Book[i].showBook();               
            }
            if(index==0){
                System.out.print("没有图书信息!");
            }
        }
    //**************************************
    public void queryByBookNo(){                 //1.按编号查询
            String a;
            @SuppressWarnings("resource")
            Scanner in2=new Scanner(System.in);
            System.out.print("请输入要查询的图书编号:");
            a=in2.nextLine();
            if(queryBooByBookNo(a)!=-1){
            System.out.print("该图书信息为:\n");
            Book[queryBooByBookNo(a)].showBook();
            }
            else                 
                System.out.print("该图书不存在!");    
               }
    public static int queryBooByBookNo(String s){//按编号查询,s为查询的图书编号;若找到,则返回该信息的位置,否则返回-1
            int flag=-1;
            for(int i=0;i<index;i++){
                if(s.equals(Book[i].BookNo)){
                    flag=i;break;
                }
            }
    return flag;
        }
    //****************************************        
    public void queryByBookName(){               //2.按名称查询
            String a;
            @SuppressWarnings("resource")
            Scanner in1=new Scanner(System.in);
            System.out.print("请输入要查询的图书名称:");
            a=in1.nextLine();
            if(queryBooByBookName(a)!=-1){
            System.out.print("该图书信息为:\n");
            Book[queryBooByBookName(a)].showBook();
            }
            else                 
                System.out.print("该图书不存在!");                   
               }
    public int queryBooByBookName(String s){      //按名称查询,s为查询的图书名称;若找到,则返回该信息的位置,否则返回-1
            int flag=-1;
            for(int i=0;i<index;i++){
                if(s.equals(Book[i].BookName)){
                    flag=i;break;
                }
            }
            return flag;
        }
    //*************************************
    public void queryByBookAuthor(){                 //3.按作者查询
            String a;
            @SuppressWarnings("resource")
        Scanner in1=new Scanner(System.in);
            System.out.print("请输入要查询的图书作者:");
            a=in1.nextLine();
            if(queryBooByBookAuthor(a)!=-1){
             System.out.print("该图书信息为:\n");
            Book[queryBooByBookAuthor(a)].showBook();
            }
            else                
                System.out.print("该图书不存在!");                 
               }
    public int queryBooByBookAuthor(String s){      //按作者查询,s为查询的图书作者;若找到,则返回该信息的位置,否则返回-1
            int flag=-1;
            for(int i=0;i<index;i++){
                if(s.equalsIgnoreCase(Book[i].BookAuthor)){
                    flag=i;break;
                }
            }
            return flag;
        }        
    //```````````````````````删除图书信息``````````````````````````
    public void deleteByBookNo(){                  //删除指定编号的图书信息
   String b;
   @SuppressWarnings("resource")
   Scanner in2=new Scanner(System.in);
   System.out.print("请输入要删除图书的编号");
   b=in2.nextLine();
    if (queryBooByBookNo(b)!=-1){                    //判断该图书是否存在
                  for(int i=queryBooByBookNo(b);i<index-1;i++){
                  Book[i]=Book[i+1];        
                  } 
                  System.out.print("删除成功!");
                  index--;
                  }
    else
        System.out.print("该图书不存在!");    
       }
    //```````````````````````修改图书信息``````````````````````````
        @SuppressWarnings("resource")
    public void reviseByBookNo(){                  // 按编号查找该图书并修改图书内容
        String b;
        int n;
    Scanner in2=new Scanner(System.in);
    Scanner in3=new Scanner(System.in);
    System.out.print("请输入要修改的图书编号");
    b=in3.nextLine();  
                      if(queryBooByBookNo(b)!=-1){         //判断该图书是否存在
                        int i=queryBooByBookNo(b);
                        System.out.println("请选择要修改的图书信息:");
                        System.out.println("1-修改图书编号");
                        System.out.println("2-修改图书名称");
                        System.out.println("3-修改图书作者");
                        System.out.println("4-修改所有信息");
                         n=in2.nextInt();
                         while(n<0||n>4){
                                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<AllBook.index;i++){
         if(Borrow.BoCs<AllBook.Book[i].cs){
             Borrow.BoCs=AllBook.Book[i].cs;
         }         
     }return Borrow.BoCs;
}
    public void findByTj(){   //按借阅次数查询
     int a= findBoCs();
     int c=0;
    System.out.print("最大借阅次数为"+a+",请输入要查询的借阅次数:");
    @SuppressWarnings("resource")
    Scanner in1=new Scanner(System.in);
    int b;
    b=in1.nextInt();    
    if(b<=a){
         System.out.print("\n借阅次数为"+b+"的图书信息如下:\n");
         for(int  i=0;i<AllBook.index;i++){
          if(AllBook.Book[i].cs==b){
            AllBook.Book[i].showBook();
             c++;
             }
          }
           if(c==0){
              System.out.print("\n不存在借阅次数为"+b+"的图书");
             }
          }
    else
    System.out.print("该借阅次数超过最大借阅次数!");
}
    
    //-------------------显示所有在库图书----------------
    public void showzkBook(){
        int c=0;
        System.out.print("所有在库的图书信息为:\n");
        for(int  i=0;i<AllBook.index;i++){
            if(AllBook.Book[i].zk==1){
                AllBook.Book[i].showBook();
                c++;
            }
        }
        if(c==0){
            System.out.print("无在库图书!");
        }
    }
    //-------------------显示所有不在库图书----------------
    public void showbzkBook(){
        int c=0;
        System.out.print("所有不在库的图书信息为:\n");
        for(int  i=0;i<AllBook.index;i++){
            if(AllBook.Book[i].zk==0){
                AllBook.Book[i].showBook();
                c++;
            }
        }
        if(c==0){
        System.out.print("无不在库图书!");
        }
    }  
    //----------------------图书查询管理----------------------
    public void findbook(){
     @SuppressWarnings("resource")
    Scanner in=new Scanner(System.in);
     String b;
     System.out.print("请输入要查找图书的编号:\n");
     b=in.nextLine();
     int a=AllBook.queryBooByBookNo(b);
    if(a!=-1){
      if(AllBook.Book[a].zk==1)             
          AllBook.Book[a].showBook();    
      else
          {
          AllBook.Book[a].showBook();
          showlendInfo(b);   }     
    }
    else
         System.out.print("图书不存在!");     
}
}

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;i<Student.length;i++){
               Student[i]=new Student();
               }
           }
       //----------------输入多个学生信息---------------
       public void inputAS(){
            int a=1;
               for(int i=index;i<Student.length;i++){
               if(a==1){
                  System.out.print("下面录入第"+(index+1)+"个学生的信息:\n");
                Student[i].inputStudent();
                index++;
                System.out.print("继续添加请按1,停止添加请按0:");
                   int b;
                   @SuppressWarnings("resource")
                Scanner in1=new Scanner(System.in);
                   b=in1.nextInt();
                   switch(b){
                   case 0: a=0;break;
                   default: break;
                               }
                       }
            }               
       }    
       //`````````````````````````浏览学生信息````````````````````````
       public void showAllStudent(){//显示所有学生信息
               for(int i=0;i<index;i++){
                   System.out.print("\n下面输出第"+(i+1)+"个学生的信息:\n");
                Student[i].showStudent();             
                }
               if(index==0){
                   System.out.print("没有学生信息!");
               }
           } 
           @SuppressWarnings("resource")
    public void queryByStudentNo(){                 //1.按学号查询
               String a;
               int c;
               Scanner in1=new Scanner(System.in);
               System.out.print("请输入要查询的学生编号:");
               a=in1.nextLine();
               c=queryStuByStudentNo(a);
               if(c!=-1){
                System.out.print("该学生信息为:\n");
             Student[queryStuByStudentNo(a)].showStudent();
               }
               else                  
                   System.out.print("该学生不存在!");                
                  }
       public static int queryStuByStudentNo(String s){//按学号查询,s为查询的学生学号;若找到,则返回该信息的位置,否则返回-1
               int flag=-1;
               for(int i=0;i<index;i++){
                   if(s.equalsIgnoreCase(Student[i].StudentNo)){
                       flag=i;break;
                   }
               }
               return flag;
           }
    //*******************************************
           @SuppressWarnings("resource")
    public void queryByStudentName(){                 //2.按名字查询
               String a;
               Scanner in1=new Scanner(System.in);
               System.out.print("请输入要查询的学生名字:");
               a=in1.nextLine();
               if(queryStuByStudentName(a)!=-1){
                System.out.print("该学生信息为:\n");
              Student[queryStuByStudentName(a)].showStudent();
               }
               else            
                   System.out.print("该学生不存在!");    
               
                  }
       public int queryStuByStudentName(String s){       //按名字查询,s为查询的学生名字;若找到,则返回该信息的位置,否则返回-1
               int flag=-1;
               for(int i=0;i<index;i++){
                   if(s.equalsIgnoreCase(Student[i].StudentName)){
                       flag=i;break;
                   }
                   else
                       continue;
               }
               return flag;
           }
       //*******************************************
           @SuppressWarnings("resource")
    public void queryByStudentClass(){                 //3.按班级查询
               String a;
               Scanner in1=new Scanner(System.in);
               System.out.print("请输入要查询的学生班级:");
               a=in1.nextLine();
               if(queryStuByStudentClass(a)!=-1){
                System.out.print("该学生信息为:\n");
              Student[queryStuByStudentClass(a)].showStudent();
               }
               else                 
                   System.out.print("该学生不存在!");                   
                  }
       public int queryStuByStudentClass(String s){         //按班级查询,s为查询的学生班级;若找到,则返回该信息的位置,否则返回-1
               int flag=-1;
               for(int i=0;i<index;i++){
                   if(s.equalsIgnoreCase(Student[i].StudentClass)){
                       flag=i;break;
                   }
                   else
                       continue;
               }
               return flag;
           }         
       //```````````````````````删除学生信息``````````````````````````
        @SuppressWarnings("resource")
    public void deleteByStudentNo(){                  //删除指定学号的学生信息
         String b;
         Scanner in2=new Scanner(System.in);
         System.out.print("请输入要删除学生的学号");
         b=in2.nextLine();
          if (queryStuByStudentNo(b)!=-1){
                        for(int i=queryStuByStudentNo(b);i<index;i++){
                        Student[i]=Student[i+1];
                                              }
                          index--;
                        System.out.print("删除成功!");
                        }
          else
              System.out.print("该学生不存在!");    
            }      
       //```````````````````````修改学生信息``````````````````````````
     @SuppressWarnings("resource")
    public void reviseByStudentNo(){          // 按编号查找该图书并修改图书内容
            String b;
            int n;
         Scanner in2=new Scanner(System.in);
         Scanner in3=new Scanner(System.in);
         System.out.print("请输入要修改的学生编号:");
         b=in2.nextLine();      
                        if(queryStuByStudentNo(b)!=-1){        
                          int i=queryStuByStudentNo(b);
                          System.out.println("请选择要修改的学生信息:");
                          System.out.println("1-修改学生学号");
                          System.out.println("2-修改学生姓名");
                          System.out.println("3-修改学生班级");
                          System.out.println("4-修改所有信息");
                           n=in2.nextInt();
                          while(n<0||n>4){
                              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代码实现图书管理系统”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI