Java初学 -- 根据书籍类制作一个简易的控制台图书管理系统

刚刚开始学java

因为练习写了一个简陋的控制台图书管理系统

欢迎各位大佬批评指正

 

首先是书籍类

package cn.com.zx.BookDemo;

import java.util.ArrayList;

public class Book {
    // 书籍包含书名,id,价格,出版年份,作者,出版社,在库数量,出库数量;
    String name;

    public int getInNum() {
        return inNum;
    }

    public void setInNum(int inNum) {
        this.inNum = inNum;
    }

    public int getOutNum() {
        return outNum;
    }

    public void setOutNum(int outNum) {
        this.outNum = outNum;
    }

    int id;
    double price;
    int year;
    String wirter;
    String clas;
    int inNum;
    int outNum;

    public Book(String _name, int _id, double _price, int _year,String _wirter,String _clas,int _inNum , int _outNum) {
        name = _name;
        id = _id;
        price = _price;
        year = _year;
        wirter = _wirter;
        clas = _clas;
        inNum = _inNum;
        outNum = _outNum;

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public String getWirter() {
        return wirter;
    }

    public void setWirter(String wirter) {
        this.wirter = wirter;
    }

    public String getClas() {
        return clas;
    }

    public void setClas(String clas) {
        this.clas = clas;
    }

    public ArrayList title() {
        ArrayList msg = new ArrayList();
        msg.add("书籍名称");
        msg.add("书号");
        msg.add("价格");
        msg.add("年份");
        msg.add("作者");
        msg.add("出版社");
        msg.add("在库量");
        msg.add("出库量");
        return msg;
    }

    public ArrayList value() {
        ArrayList msg = new ArrayList();
        msg.add(this.getName());
        msg.add(this.getId());
        msg.add(this.getPrice());
        msg.add(this.getYear());
        msg.add(this.getWirter());
        msg.add(this.getClas());
        msg.add(this.getInNum());
        msg.add(this.getOutNum());
        return msg;
    }

    public void showMessage() {
    // 打印信息
        for (int i = 0; i < title().size(); i++) {
            System.out.print(value().get(i)+"\t");
        }
        System.out.println();
    }


} 
  

然后就是主程序

package cn.com.zx.BookDemo;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * 根据书籍类制作一个简易的图书管理系统
 * 
 */

public class Demo_class {

    public static void main(String[] args) throws Exception {

        //初始化数据
        Book book = new Book("人间失格",1901 , 40.00,2016,"太宰治","北京出版社",90,10);
        Book book1 = new Book("狂人日记",1902 , 80.00,2017,"鲁迅","新华出版社",80,20);
        Book book2 = new Book("高等数学",1903 , 100.00,2019,"华罗庚","清华出版社",70,30);
        ArrayList books = new ArrayList();
        books.add(book);
        books.add(book1);
        books.add(book2);

        Scanner sc = new Scanner(System.in);
        while (true) {
            index();
            try {
                int chose = sc.nextInt();
                if (chose == 1) {
                    //显示全部书籍信息
                    title(book);
                    check(books);
                    back();
                } else if (chose == 2) {
                    //添加书籍操作
                    add(book, books);
                    back();
                } else if (chose == 3) {
                    //删除书籍操作
                    del(books);
                    back();
                } else if (chose == 4) {
                    //修改操作
                    change(book, books);
                    back();
                }else if (chose == 5) {
                    //借书操作
                    Borrowing(books);
                    back();
                } else if (chose == 6) {
                    //还书操作
                    Returning(books);
                    back();
                }else if (chose == 0){
                    System.out.println("退出成功!");
                    sc.close();
                    System.exit(0);
                }
                else {
                    System.out.println("输入有误!请重新输入!");
                }
            } catch (Exception e) {
                System.out.println("输入有误!请重新输入!");
            }
            sc = new Scanner(System.in);
        }
    }

    private static void index(){
        //主页面
        System.out.println("-----图书管理系统-----");
        System.out.println("  1.查询\t 2.添加");
        System.out.println("  3.删除\t 4.修改");
        System.out.println("  5.借书\t 6.还书");
        System.out.println("  0.退出程序");
        System.out.println("请选择要执行的操作:");

    }

    private static void title(Book book){
        //列表题
        for (int i = 0; i  books){
        for (int i = 0; i < books.size(); i++) {
            books.get(i).showMessage();
        }
    }

    private static void add(Book book ,ArrayList books){
        boolean flag = true;
        Scanner add_sc = new Scanner(System.in);
        ArrayList msg_add = new ArrayList();
        for (int i = 0; i  books){
        Scanner del_sc = new Scanner(System.in);
        System.out.println("请输入要删除的书号:");
        int id = del_sc.nextInt();
        for (int i = 0; i  books){
        Scanner cg_sc = new Scanner(System.in);
        Scanner cg_sc1 = new Scanner(System.in);
        System.out.println("请输入要修改的书号:");
        int id = cg_sc.nextInt();
        for (int i = 0; i  msg_cg = new ArrayList();
                for (int j = 0; j  books){
        Scanner bor_sc = new Scanner(System.in);
        System.out.println("请输入要借的书号:");
        int id = bor_sc.nextInt();
        for (int i = 0; i  books){
        Scanner re_sc = new Scanner(System.in);
        System.out.println("请输入要归还的书号:");
        int id = re_sc.nextInt();
        for (int i = 0; i 

然后就是运行界面

Java初学 -- 根据书籍类制作一个简易的控制台图书管理系统_第1张图片

也许学到后面更高级的东西会修改整理,或者直接图形化界面就就更好了

路还很长,慢慢学吧......

你可能感兴趣的:(初学)