Java 图书馆库存管理系统(附加用户购买结账系统)

01.package Library;   
02.  
03.import java.io.Serializable;  
04.  
05.public class Book implements Serializable{  
06.  
07.    private int bookId;  
08.    private String bookName;  
09.    private String auther;  
10.    private String pubDate;  
11.    private double price;  
12.    private int store;  
13.    public int getBookId() {  
14.        return bookId;  
15.    }  
16.    public void setBookId(int bookId) {  
17.        this.bookId = bookId;  
18.    }  
19.    public String getBookName() {  
20.        return bookName;  
21.    }  
22.    public void setBookName(String bookName) {  
23.        this.bookName = bookName;  
24.    }  
25.    public String getAuther() {  
26.        return auther;  
27.    }  
28.    public void setAuther(String auther) {  
29.        this.auther = auther;  
30.    }  
31.    public String getPubDate() {  
32.        return pubDate;  
33.    }  
34.    public void setPubDate(String pubDate) {  
35.        this.pubDate = pubDate;  
36.    }  
37.    public double getPrice() {  
38.        return price;  
39.    }  
40.    public void setPrice(double price) {  
41.        this.price = price;  
42.    }  
43.    public int getStore() {  
44.        return store;  
45.    }  
46.    public void setStore(int store) {  
47.        this.store = store;  
48.    }  
49.    public Book(int bookId, String bookName, String auther, String pubDate,  
50.            double price, int store) {  
51.        super();  
52.        this.bookId = bookId;  
53.        this.bookName = bookName;  
54.        this.auther = auther;  
55.        this.pubDate = pubDate;  
56.        this.price = price;  
57.        this.store = store;  
58.    }  
59.    public Book() {  
60.        // TODO Auto-generated constructor stub  
61.    }  
62.      
63.  
64.}</strong></span><span style="font-size:18px;font-weight: bold;">  
65.</span>  

01.package Library;  
02.  
03.import java.io.FileInputStream;  
04.import java.io.FileNotFoundException;  
05.import java.io.FileOutputStream;  
06.import java.io.IOException;  
07.import java.io.ObjectInputStream;  
08.import java.io.ObjectOutputStream;  
09.import java.util.ArrayList;  
10.import java.util.List;  
11.  
12.public class BookBiz {  
13.    private List<Book> bookList =new ArrayList<Book>();  
14.      
15.    public BookBiz(){  
16.        readFile();  
17.        if(bookList.size()==0){  
18.            Book book=new Book(10001,"鬼吹灯","天下霸唱","2006-1-1",34,3);  
19.            insertBook(book);  
20.             book=new Book(10002,"魔戒","莫尔斯","2006-3-1",334,300);  
21.            insertBook(book);  
22.             book=new Book(10003,"哈利波特","罗琳","2006-1-1",34,3);  
23.            insertBook(book);  
24.             book=new Book(10004,"时间机器人","威尔","2006-3-1",90,30);  
25.            insertBook(book);  
26.             book=new Book(10005,"宇宙奥秘","霍金","2006-1-1",89,79);  
27.            insertBook(book);  
28.        }  
29.    }  
30.      
31.    public void insertBook(Book book){  
32.        bookList.add(book);  
33.        saveFile();  
34.    }  
35.    public void deleteBook(int id){  
36.        for(int i=0;i<bookList.size();i++){  
37.            Book book =bookList.get(i);  
38.            if(book.getBookId()==1){  
39.                bookList.remove(i);  
40.                saveFile();  
41.                return;  
42.            }  
43.        }  
44.    }  
45.    public void updateBook(Book book){  
46.        for(int i=0;i<bookList.size();i++){  
47.            Book bk=bookList.get(i);  
48.            if(bk.getBookId()==book.getBookId()){  
49.                bk.setAuther(book.getAuther());  
50.                bk.setBookId(book.getBookId());  
51.                bk.setPrice(book.getPrice());  
52.                bk.setStore(book.getStore());  
53.                bk.setPubDate(book.getPubDate());  
54.                saveFile();  
55.                return;  
56.                  
57.            }  
58.        }  
59.    }  
60.    public List<Book> selectBooks(){  
61.          
62.        return bookList;      
63.    }  
64.    public Book selectBook(int id ){  
65.          
66.        Book book=new Book();  
67.        for (int i = 0; i < bookList.size(); i++) {  
68.            book=bookList.get(i);  
69.            if(book.getBookId()==id){  
70.                return book;  
71.            }  
72.        }  
73.        return null;  
74.    }  
75.public Book selectBook2(int id,int store ){  
76.          
77.        Book book=new Book();  
78.        for (int i = 0; i < bookList.size(); i++) {  
79.            book=bookList.get(i);  
80.            if(book.getBookId()==id){  
81.                int st=book.getStore()-store;  
82.                book.setStore(st);  
83.                return book;  
84.            }  
85.        }  
86.        return null;  
87.    }  
88.public void readFile(){  
89.    ObjectInputStream ois=null;  
90.    FileInputStream fis=null;  
91.    String name="E:\\Android\\workspace\\MyOopBook\\src\\book.txt";  
92.        try {fis=new FileInputStream(name);  
93.        ois=new ObjectInputStream(fis);   
94.        bookList=(List<Book>) ois.readObject();         
95.}catch (FileNotFoundException e) {  
96.    // TODO Auto-generated catch block  
97.    e.printStackTrace();  
98.} catch (IOException e) {  
99.    // TODO Auto-generated catch block  
100.    e.printStackTrace();  
101.} catch (ClassNotFoundException e) {  
102.    // TODO Auto-generated catch block  
103.    e.printStackTrace();  
104.}  
105.finally{  
106.    try {  
107.        if(ois!=null){  
108.            ois.close();  
109.        }  
110.    } catch (IOException e) {  
111.
  • 4
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值