Java----图书馆借阅系统Main.java
package com.src1.booksystem;
import com.src1.booksystem.booklist.BookList;
import com.src1.booksystem.users.AdminUser;
import com.src1.booksystem.users.NormalUser;
import com.src1.booksystem.users.User;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
//1.准备书籍
BookList bookList =new BookList();
/
/2登录
User user =login();
while(true){
int chioce = u();
//3.根据选择调⽤⽅法
user.doOperation(chioce, bookList);
}
}
public static User login(){
Scanner scanner =new Scanner(System.in);
System.out.println("请输⼊⽤户名:");
String name = Line();
if("admin".equals(name)){
System.out.println("请输⼊管理员密码:");
String password = Line();
if("admin".equals(password)){
System.out.println("hello! 尊敬的管理员! 欢迎来到藏经阁");
return new AdminUser(name);
}else{
System.out.println("密码错误,进⼊⽤户端!");
System.out.println("hello! "+ name+" 欢迎来到藏经阁");
return new NormalUser(name);
}
}else{
System.out.println("hello! "+ name+" 欢迎来到藏经阁");
return new NormalUser(name);
}
}
}
package user
AdminUser.java
public class AdminUser extends User {
@Override
public int menu(){
Scanner scanner =new Scanner(System.in);
System.out.println("1.查图书");
System.out.println("2.新增书籍");
System.out.println("3.删除书籍");
System.out.println("4.书籍列表");
System.out.println("0.退出系统");
int chioce = Int();
return chioce;
}
public AdminUser(String name){
super(name);
this.operations =new IOperation[]{
new ExitOperation(),
new FindOperation(),
new AddOperation(),
new DelOperation(),
new DisplayOperation()
};
}
}
NormalUser.java
public class NormalUser extends User {
@Override
public int menu(){
Scanner scanner =new Scanner(System.in);
System.out.println("1.查图书");
System.out.println("2.借阅书籍");
System.out.println("3.归还书籍");
System.out.println("4.书籍列表");
System.out.println("0.退出系统");
int chioce = Int();
return chioce;
}
public NormalUser(String name){
super(name);
this.operations =new IOperation[]{
new ExitOperation(),
new FindOperation(),
new BorrowOperation(),
new ReturnOperation(),
new DisplayOperation()
};
}
}
User.java
package com.src1.booksystem.users;
import com.src1.booksystem.booklist.BookList; import com.src1.booksystem.operation.IOperation;
abstract public class User {
public String name;
public IOperation[] operations;
/**
* 如果没有menu 就不能通过user访问
*/
public abstract int menu();
public void doOperation(int chioce, BookList bookList){ //数组当中元素的对象,通过.调⽤对应operation⽅法
operations[chioce].work(bookList);
}
public User(String name){
this.name = name;
}
}
package book
book.java
public class Book {
private String name;
private String author;
private int price;
private String type;
private boolean isBorrowed;
public Book(String name, String author,int price){ this.name = name;
this.author = author;
this.price = price;
}
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 boolean isBorrowed(){
return isBorrowed;
}
public void setBorrowed(boolean borrowed){
isBorrowed = borrowed;
}
@Override
public String toString(){
return"["+
"书名:"+ name +
", 作者:"+ author +
", 价格:"+ price +","+
(isBorrowed ?"已借出":"未借出")+"]";
}
}
package booklist
BookList.java
package com.src1.booksystem.booklist;
import com.src1.booksystem.book.Book;
public class BookList {
java图书馆最新private Book[] books;
private int usedSize;
public BookList(){
this.books =new Book[10];
this.books[0]=new Book("西游记","吴承恩",13); this.books[1]=new Book("⽔浒传","施耐庵",14); this.books[2]=new Book("三国演义","罗贯中",15); this.usedSize =3;
}
public int getUsedSize(){
return usedSize;
}
public void setUsedSize(int usedSize){
this.usedSize = usedSize;
}
public Book getBook(int pos){
return books[pos];
}
public void setBooks(int pos,Book book){
this.books[pos]= book;
}
}
package operation AddOperation
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论