简易图书管理系统

一款简单的java小程序

图片发自简书App

首先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;
                }
            }
        }
    }
}

完结撒花

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,957评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,388评论 25 708
  • 0079 住酒店用什么水煮老白茶? 摘要:酒店里煮老白茶,用什么水要注意,北方尤其是西北地区水质偏硬,有的甚至水质...
    白茶笔记阅读 477评论 0 0
  • 每日赠言:自信不是争取到的,是打造出来的,不是一天两天、也不是一个星期,而是经年累月打造出来的。
    超逸璎漫步云端阅读 222评论 0 0
  • 简介 今天是web开发笔记-css介绍(1)后续介绍. 内容 属性选择器[attribute], 匹配所有指定属性...
    小貔阅读 352评论 0 0