中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何用Java代碼實現圖書管理系統

發布時間:2022-02-25 13:53:35 來源:億速云 閱讀:128 作者: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

白山市| 通榆县| 丰镇市| 利川市| 甘孜县| 济宁市| 苍南县| 米泉市| 金山区| 灵台县| 鄂伦春自治旗| 梅河口市| 山阳县| 三门县| 获嘉县| 大邑县| 杨浦区| 滨州市| 府谷县| 耿马| 新河县| 广丰县| 楚雄市| 旬邑县| 通道| 五台县| 无极县| 安平县| 潼关县| 岱山县| 新沂市| 合水县| 临邑县| 武强县| 稻城县| 胶州市| 高平市| 根河市| 兴文县| 无锡市| 精河县|