2021-04-11 图书管理系统

package Book;

import java.util.Scanner;

public class Demo {

public static class BookMgr {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //初始化书本信息
        String[] bookNames = new String[6];
        int[] borrowDates = new int[6];
        int[] borrowCounts = new int[6];
        int[] states = new int[6];


        bookNames[0] = "钢铁是怎样炼成的";
        borrowDates[0] = 15;
        borrowCounts[0] = 16;
        states[0] = 0;//0:可借阅 1:已借出

        bookNames[1] = "格林童话";
        borrowDates[1] = 0;
        borrowCounts[1] = 0;
        states[1] = 1;//0:可借阅 1:已借出

        bookNames[2] = "Java开发";
        borrowDates[2] = 0;
        borrowCounts[2] = 0;
        states[2] = 0;//0:可借阅 1:已借出

        int num = -1;//初始化用户输入的数字
        boolean flag = true;//true:不退出系统 false:退出系统
        do{
            System.out.println("************欢迎使用MiNi图书管理系统**********");
            System.out.println("\t\t\t\t\t1.新增图书");
            System.out.println("\t\t\t\t\t2.查看图书");
            System.out.println("\t\t\t\t\t3.借阅图书");
            System.out.println("\t\t\t\t\t4.归还图书");
            System.out.println("\t\t\t\t\t5.删除图书");
            System.out.println("\t\t\t\t\t6.退出系统");

            System.out.print("\n请选择:");
            int choose = sc.nextInt();
            while(choose<0 || choose>6){
                System.out.print("输入有误,重新输入:");
                choose = sc.nextInt();
            }
            switch(choose){
                case 1:
                    System.out.println("************1.新增图书**********");
                    System.out.print("请输入新增图书的名字:");
                    String addBook = sc.next();
                    boolean isAdd = false;//false:不能添加图书  true:可以添加图书
                    //遍历数组,查找新增图书的位置
                    for(int i =1;i 31){
                                System.out.print("输入有误,重新输入:");
                                borrowRiQi = sc.nextInt();
                            }
                            System.out.println("借阅成功!!!");
                            //更改借阅日期
                            borrowDates[i] = borrowRiQi;
                            //更新借阅状态
                            states[i] = 1;
                            //更新借阅次数
                            borrowCounts[i]++;
                            break;
                        }else if(bookNames[i] != null && bookNames[i].equals(borrowName) && states[i] == 1){
                            //如果可以找到书,且书的状态是已借出,不能借阅
                            isBorrow = true;
                            System.out.println("书已经借出,不能重复借阅!");
                            break;
                            //if(bookNames[i] == null)
                            //if(!bookNames[i].equals(borrowName))
                        }/*else if(bookNames[i] == null){
          isBorrow = false;
          break;
        }*/
                    }
                    if(!isBorrow){
                        //bookNames[i] == null,说明 找不到书
                        System.out.println("抱歉,找不到该书!!!");
                        break;
                    }
                    break;
                case 4:
                    System.out.println("4.归还图书");
                    System.out.print("请输入您要归还图书的名字:");
                    String returnName = sc.next();
                    boolean isReturn = false;//true:能归还
                    for(int i = 0;i 31 || returnRiQi 31){
                                    System.out.print("输入的日期有误,重新输入:");
                                    returnRiQi = sc.nextInt();
                                }else if(returnRiQi

}

你可能感兴趣的:(2021-04-11 图书管理系统)