简易图书管理系统

作者: TY_ | 来源:发表于2016-08-09 08:56 被阅读700次

    一款简单的java小程序

    简易图书管理系统

    首先Book类,定义方法

    public class Book {
        private String bookName; // 图书名称
        public Book(String bookName) {
            super();
            this.bookName = bookName;
        }
        public String getBookName() {
            return bookName;
        }
        public void setBookName(String bookName) {
            this.bookName = bookName;
        }
        @Override
        public String toString() {
            return "\t" + bookName;
        }
    }
    

    Save类,定义数组

    public class Save {
        // 静态数组
        static String[] books = { "道德经", "山海经", "Android艺术探索", "论程序员素养" };
        // 动态数组
        Books[] books1 = new Books[10];
        // 初始化
        public void jieyue() {
            books1[0] = new Books();
            books1[0].names = "ss";
        }
        public class Books {
            String names;
        }
    }
    

    这里为主程序

    public class System_1 extends Save {
    static String[] books1 = new String[5];
    public static void main(String[] args) {
     // 第一界面
     while (true) {
      Scanner s = new Scanner(System.in);
      System.out.print("请输入用户名:");
      String username = s.next();
      System.out.print("请输入密码:");
      String passward = s.next();
      System.out.println("                  欢迎进入图书管理系统");
      // 主界面
      while (true) {
       System.out.println(" 1.借        书");
       System.out.println(" 2.借阅信息");
       System.out.println(" 3.还        书");
       System.out.println(" 4.退        出");
       System.out.println("请输入对应编号:");
       int a = s.nextInt();
       switch (a) {
       case 1:
        // 子a1界面
        System.out.println("                  借        书");
        System.out.println("    1.道德经");
        System.out.println("    2.山海经");
        System.out.println("    3.Android艺术探索");
        System.out.println("    4.论程序员素养");
         int a1 = s.nextInt();
         switch (a1) {
         case 1:
          System.out.println("\n" + " 您已成功借阅《"
            + books[0] + "》!");
          books1[0] = "道德经";
          break;
         case 2:
          System.out.println("\n" + " 您已成功借阅《"
    + books[1] + "》!");
                            books1[1] = "山海经";
                            break;
                        case 3:
                            System.out.println("\n" + "                您已成功借阅《"
                                    + books[2] + "》!");
                            books1[2] = "Android艺术探索";
                            break;
                        case 4:
                            System.out.println("\n" + "                您已成功借阅《"
                                    + books[3] + "》!");
                            books1[3] = "论程序员素养";
                            break;
                        default:
                            System.out.println("请选择正确编号!");
                            break;
                        }
                        break;
                    // 子a2界面
    case 2:
                        System.out.println("                  借阅信息");
                        if (books1[0] == null && books1[1] == null
                                && books1[2] == null && books1[3] == null) {
                            System.out.println("                  您的书库空无一物!");
                        } else {
                            String xa = null, xb = null, xc = null, xd = null;
                            if (books1[0] == null) {
                                xa = " ";
                            } else
                                xa = books1[0];
                            if (books1[1] == null) {
                                xb = " ";
                            } else
                                xb = books1[1];
                            if (books1[2] == null) {
                                xc = " ";
                            } else
                                xc = books1[2];
                            if (books1[3] == null) {
                                xd = " ";
                            } else
                                xd = books1[3];
                            System.out.println("您借阅到的书有");
                            System.out.println("       " + xa + "\r" + xb + "\r"
                                    + xc + "\r" + xd);
                        }
                        break;
                    // 子a3界面
    case 3:
                        System.out.println("                  还书");
                        if (books == null) {
                            System.out.println("        请确认借阅情况!");
                        } else {
                            books = null;
                            System.out.println("              已归还");
                        }
                        break;
                    // 子a4界面
                    case 4:
                        System.out.println("                  您已成功退出!");
                        System.exit(0);
                        break;
                    default:
                        System.out.println("请选择正确编号!");
                        break;
                    }
                }
            }
        }
    }
    
    

    完结撒花

    相关文章

      网友评论

        本文标题:简易图书管理系统

        本文链接:https://www.haomeiwen.com/subject/ibarsttx.html