当前位置 博文首页 > 是琳琳呀!的博客:图书馆系统(Java)
用户
package user;
import book.BookList;
import operation.IOperation;
public abstract class User {
public String name;
public IOperation[] operations;
public User(String name){
this.name=name;
}
public abstract int menu();
public void doOperation(int choice, BookList bookList){
//看这个数组当中 存的是那些操作
this.operations[choice].work(bookList);
}
}
import operation.*;
import java.util.Scanner;
//管理员
public class AdminUser extends User{
public AdminUser(String name) {
super(name);
this.operations=new IOperation[]{
new ExitOperation(),
new FindOperation(),
new AddOperation(),
new DelOperation(),
new DisplayOperation()
};
}
//返回你要执行的菜单
@Override
public int menu() {
Scanner scanner=new Scanner(System.in);
System.out.println("管理员的菜单!");
System.out.println("======================");
System.out.println("hello"+this.name+"欢迎来到图书馆系统!");
System.out.println("1.查找图书");
System.out.println("2.新增图书");
System.out.println("3.删除图书");
System.out.println("4.显示图书");
System.out.println("0.退出系统");
System.out.println("======================");
int choice=scanner.nextInt();
return choice;
}
}
package user;
import operation.*;
import java.util.Scanner;
//普通用户
public class NormalUser extends User{
public NormalUser(String name) {
super(name);
this.operations=new IOperation[]{
new ExitOperation(),
new FindOperation(),
new BorrowOperation(),
new ReturnOperation()
};
}
@Override
public int menu() {
Scanner scanner=new Scanner(System.in);
System.out.println("普通用户的菜单!");
System.out.println("======================");
System.out.println("hello"+this.name+"欢迎来到图书馆系统!");
System.out.println("1.查找图书");
System.out.println("2.借阅图书");
System.out.println("3.归还图书");
System.out.println("0.退出系统");
System.out.println("======================");
int choice=scanner.nextInt();
return choice;
}
}
图书信息
package book;
public class Book {
private String name;
private String author;
private int price;
private String type;
private boolean status;//false
public Book(String name,String author,int price,String type) {
this.name = name;
this.author=author;
this.price=price;
this.type=type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public boolean isStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
@Override
public String toString() {
return "Book{" +
"name='" + name + '\'' +
", author='" + author + '\'' +
", price=" + price +
", type='" + type + '\'' + ",status="+
((status==true)?" 借出 ":" 未借出 ")+
'}';
}
}
package book;
public class BookList {
private Book[] books;
private int usedSize;
public BookList() {
this.books = new Book[10];
books[0]=new Book("三国演义","罗贯中",72,"小说");
books[1]=new Book("西游记","施耐庵",32,"小说");
books[2]=new Book("水浒传","施耐庵",58,"小说");
this.usedSize=3;
}
//尾插法
public void setBooks(int pos,Book book){
this.books[pos]=book;
}
public Book getBook(int pos){
return this.books[pos];
}
public int getUsedSize() {
return usedSize;
}
public void setUsedSize(int usedSize) {
this.usedSize