JAVA小白学习的第一个代码—图书管理系统

小白在实训的学习实训的第二周开始写图书管理系统代码,接下来是记录学习的过程。
创建了一个Library 类和Booktest类
创建Library类对图书管理系统 创建方法,然后在写构造方法

package com.lenovo.www.entity;

public class Library {

    private int Id;
    private String BookName;
    private String Author;
    private String Reader;
    private String price;
    private String TypeId;
    private String BookDesc;
    public Library() {}


    public Library(int id, String bookName, String author, String reader, String price, String typeId,
            String bookDesc) {
        super();
        Id = id;
        BookName = bookName;
        Author = author;
        Reader = reader;
        this.price = price;
        TypeId = typeId;
        BookDesc = bookDesc;
    }


    public int getId() {
        return Id;
    }
    public void setId(int id) {
        Id = id;
    }
    public String getBookName() {
        return BookName;
    }
    public void setBookName(String bookName) {
        BookName = bookName;
    }
    public String getAuthor() {
        return Author;
    }
    public void setAuthor(String author) {
        Author = author;
    }
    public String getReader() {
        return Reader;
    }
    public void setReader(String reader) {
        Reader = reader;
    }
    public String getPrice() {
        return price;
    }
    public void setPrice(String price) {
        this.price = price;
    }
    public String getTypeId() {
        return TypeId;
    }
    public void setTypeId(String typeId) {
        TypeId = typeId;
    }
    public String getBookDesc() {
        return BookDesc;
    }
    public void setBookDesc(String bookDesc) {
        BookDesc = bookDesc;
    }

}

用ArrayList进行储存信息,if  ....else语句循环执行,创建扫描器,使用户可以输入

package com.lenovo.www.entity;
/**
* private int id;
private String bookName;// 图书名称
private String author;// 作者
private String reader;// 借阅人
private String price;// 图书价格
private String TypeId;// 图书类别
private String bookDesc;// 备注
*/

import java.awt.print.Book;
import java.util.ArrayList;
import java.util.Scanner;

public class Booktest {
static ArrayList bookList = new ArrayList<>();

public Booktest(int i, String string, String string2, String string3, String string4, String string5,
        String string6) {
    // TODO Auto-generated constructor stub
}

public static void main(String[] args) {
    System.out.println("请输入菜单序号,");
    System.out.println("查询图书,1");
    System.out.println("添加图书,2");
    System.out.println("删除图书,3");
    System.out.println("退出程序,0");
    Scanner src = new Scanner(System.in);
    if (src.nextInt() == 1) {
        Library s1 = new Library(321, "《白鹿原》", "陈忠实", "小明", "30.00元", "文学类", "  借阅人数较多 ");
        Library s2 = new Library(322, "《西游记》", "吴承恩", "小红", "35.00元", "文学类", "   ");
        Library s3 = new Library(323, "《红楼梦》", "曹雪芹", "小白", "36.00元", "文学类", "   ");
        Library s4 = new Library(324, "《水浒传》", "施耐庵", "小黑", "37.00元", "文学类", "  未到指定日期归还 ");
        Library s5 = new Library(325, "《三国演义》", "罗贯中", "小明", "40.00元", "文学类", "   ");
        Library s6 = new Library(326, "《白夜行》", "东野奎吾", "小蓝", "35.00元", "悬疑类", "   ");

        bookList.add(s1);
        bookList.add(s2);
        bookList.add(s3);
        bookList.add(s4);
        bookList.add(s5);
        bookList.add(s6);
        for (int i = 0; i < bookList.size(); i++) {

            Library a = bookList.get(i);

            System.out.println("图书编号 : " + a.getId() + "  图书名称: " + a.getBookName() + "  作者: " + a.getAuthor()
                    + "     借阅人姓名: " + a.getReader() + " 图书价格: " + a.getPrice() + " 图书类别 :" + a.getTypeId()
                    + " 备注:  " + a.getBookDesc());
        }
    } else  {



        System.exit(0);
    }

}

}


   这是第一天的代码,日后不断完善
   写这段代码中出现了错误

Library s1 = new Library(321, “《白鹿原》”, “陈忠实”, “小明”, “30.00元”, “文学类”, ” 借**阅人数较多 “);
Library s2 = new Library(322, “《西游记》”, “吴承恩”, “小红”, “35.00元”, “文学类”, ” “);
Library s3 = new Library(323, “《红楼梦》”, “曹雪芹”, “小白”, “36.00元”, “文学类”, ” “);
Library s4 = new Library(324, “《水浒传》”, “施耐庵”, “小黑”, “37.00元”, “文学类”, ” 未到指定日期归还 “);
Library s5 = new Library(325, “《三国演义》”, “罗贯中”, “小明”, “40.00元”, “文学类”, ” “);
Library s6 = new Library(326, “《白夜行》”, “东野奎吾”, “小蓝”, “35.00元”, “悬疑类”, ” “);

****由于粗心将Library类写成了booklist**

定义的int整形类却输入了0501这种不符合int类型的数

private int id;

Library s2 = new Library(322, "《西游记》", "吴承恩", "小红", "35.00元", "文学类", "   ");
    Library s2 = new Library(0501, "《西游记》", "吴承恩", "小红", "35.00元", "文学类", "   ");(错误的) 

“`

你可能感兴趣的:(JAVA小白学习的第一个代码—图书管理系统)