DVD管理系统(增删改查)

图书管理系统(功能:增删改查)
package Dvd;

import java.util.Scanner;

public class DVD5 {

public static void main(String[] args) {
    String[] names = new String[5];
    int[] states = new int[5];
    int[] date = new int[5];
    int[] count = new int[5];
    Scanner input = new Scanner(System.in);
    names[0] = "温暖";
    names[1] = "读者";
    names[2] = "二毛记";

    states[0] = 0;// 0表示不可借 1表示可借
    states[1] = 1;
    states[2] = 0;

    date[0] = 1;
    date[1] = 2;
    date[2] = 1;

    count[0] = 0;
    count[1] = 1;
    count[3] = 1;

    int sss=0;
    do{
        //循环体
        System.out.println("欢迎进入图书管理系统:");
        System.out.println("============");
        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("=============");
        System.out.println("请输入:");
        int choose = input.nextInt();
        switch (choose) {
        case 1:
            System.out.println("请输入你要增加的图书名称:");
            String name = input.next();
            boolean flag = false;
            int index = -1;
                    for (int i = 0; i < count.length; i++) {
                            if (names[i] == null) {
                                index = i;
                                break;
                            }
                            if (names[i].equals(name)) {
                                flag = true;
                                break;
                            }
                        }
                        if (flag == true) {
                            System.out.println("你要增加的图书已经存在");
                        } else {
                            names[index] = name;
                            states[index] = 1;
                            date[index] = 1;
                            count[index] = 0;
                            System.out.println("新增成功!");
                    }
            break;
    case 2:
            System.out.println("序号\t名称\t状态\t借出日期\t借出次数");
                for (int i = 0; i < count.length; i++) {
                        if (names[i] == null) {
                            break;
                        }
                        if (states[i] == 0) {
                            System.out.println((i + 1) + "\t" + names[i] + "\t" + "不可借"
                                    + "\t" + date[i] + "\t" + count[i]);
                        } else {
                            System.out.println((i + 1) + "\t" + names[i] + "\t" + "可借"
                                    + "\t" + date[i] + "\t" + count[i]);
                        }
            }
            break;
    case 3:
            System.out.println("请输入你要删除的图书的名称:");
            String deleteName = input.next();
            flag = false;
            index = -1;
                for (int i = 0; i < count.length; i++) {
                        if (names[i] == null) {
                            break;
                        }
                        if (names[i].equals(deleteName)) {
                            flag = true;
                            index = i;
                            break;
                        }
                }
                if (flag == false) {
                    System.out.println("此图书不存在不能删除");
                    } else {
                        if (states[index] == 0) {
                        System.out.println("你要删除的图书存在,但是已经借出,删除失败!");
                        } else {
                            for (int i = index; i < count.length - 1; i++) {
                                names[i] = names[i + 1];
                                states[i] = states[i + 1];
                                date[i] = date[i + 1];
                                count[i] = count[i + 1];
                            }
                            names[names.length - 1] = null;
                            System.out.println("删除成功");
                            break;
                    }
                }
            break;
case 4:
            System.out.println("请输入你要借出的图书的名称:");
            String jieName = input.next();
            flag = false;
            index = -1;
            f   for (int i = 0; i < count.length; i++) {
                    if (names[i] == null) {
                        break;
                    }
                    if (names[i].equals(jieName)) {
                        flag = true;
                        index = i;
                        break;
                    }
            }
            if (flag == true) {
                if (states[index] == 1) {
                    System.out.println("请输入借出日期:");
                    date[index] = input.nextInt();
                    states[index] = 0;
                    count[index] += 1;
                        System.out.println("你输入的图书名称是《" + jieName + "》,借书成功");
                        } else {
                        System.out.println("你输入的这本书已经借出");
                        }
                    } else {
                        System.out.println("借出图书失败");
            }
            break;
        case 5:
            System.out.println("请输入你要归还的图书的名称:");
            String huanName = input.next();
            flag = false;
            index = -1;
                for (int i = 0; i < count.length; i++) {
                    if (names[i] == null) {
                        break;
                    }
                    if (names[i].equals(huanName)) {
                        flag = true;
                        index = i;
                        break;
                    }
                }
            if (flag == true) {
                if (states[index] == 1) {
                    System.out.println("此图书存在,但是没有借出,所以不能归还");
                } else {
                            System.out.println("请输日归还日期");
                            int huanDate = input.nextInt();
                            states[index] = 1;
                            System.out.println("借出日期" + date[index]);
                            System.out.println("归还日期" + huanDate);
                            System.out.println("租金" + (huanDate - date[index]));
                            System.out.println("您归还的图书名称是《" + huanName + "》成功");
                    }
            } else {
                System.out.println("归还失败!");
            }
            break;
case 6:
            System.out.println("退出程图书商城管理系统");
            System.exit(0);
            break;
        default:
            break;
        }
        System.out.println("请输入520返回:");
                int rr=input.nextInt();
        }while(sss==0);
    }

}

你可能感兴趣的:(DVD管理系统(增删改查))