服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Java教程 - Java图书管理系统课程设计

Java图书管理系统课程设计

2022-07-31 14:10sky丶Mamba Java教程

这篇文章主要为大家详细介绍了Java图书管理系统课程设计,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

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

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

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

文件位置

AllBook

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
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();
    }
}

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

原文链接:https://blog.csdn.net/qq_42535394/article/details/114498261

延伸 · 阅读

精彩推荐
  • Java教程基于JVM 中常见垃圾收集算法介绍

    基于JVM 中常见垃圾收集算法介绍

    下面小编就为大家分享一篇基于JVM 中常见垃圾收集算法介绍,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...

    挖坑埋你10712021-03-25
  • Java教程Java+Mysql学生管理系统源码

    Java+Mysql学生管理系统源码

    这篇文章主要为大家详细介绍了Java+Mysql学生管理系统源码,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 ...

    HelloRoot4452020-05-21
  • Java教程Java实现简单字符生成器代码例子

    Java实现简单字符生成器代码例子

    这篇文章主要介绍了Java实现简单字符生成器代码例子,本文直接给出实现代码,需要的朋友可以参考下 ...

    junjie4062019-12-21
  • Java教程如何导入spring源码到IDEA

    如何导入spring源码到IDEA

    这篇文章主要介绍了如何导入spring源码到IDEA,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友...

    small_horizon4792021-08-27
  • Java教程Spring 数据库连接池(JDBC)详解

    Spring 数据库连接池(JDBC)详解

    本篇文章主要介绍了基于Spring的JDBC基本框架搭建;基于Spring的JDBC增删改查;读取配置文件中的数据等,具有很好的参考价值。下面跟着小编一起来看下吧...

    五月的仓颉3352020-09-22
  • Java教程详解spring cloud分布式整合zipkin的链路跟踪

    详解spring cloud分布式整合zipkin的链路跟踪

    这篇文章主要介绍了详解spring cloud分布式整合zipkin的链路跟踪,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...

    IT高飞7572021-05-20
  • Java教程Java语法中Lambda表达式无法抛出异常的解决

    Java语法中Lambda表达式无法抛出异常的解决

    这篇文章主要介绍了Java语法中Lambda表达式无法抛出异常的解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐...

    小不点雨4712022-01-21
  • Java教程Java线程创建的四种方式总结

    Java线程创建的四种方式总结

    这篇文章主要介绍了Java线程创建的四种方式,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...

    威斯布鲁克.猩猩11832021-12-30