图书馆系统Java,java图书借阅管理系统

  图书馆系统Java,java图书借阅管理系统

  本文实例为大家分享了爪哇实现图书馆借阅系统的具体代码,供大家参考,具体内容如下

  Main.java

  包com。src 1。图书系统;导入com。src 1。图书系统。书单。书单;导入com。src 1。图书系统。用户。adminuser导入com。src 1。图书系统。用户。普通用户;导入com。src 1。图书系统。用户。用户;导入Java。util。扫描仪;public class Main { public static void Main(String[]args){//1 .准备书籍BookList BookList=new BookList();//2登录user user=log in();while(true){ int chio ce=user。menu();//3.根据选择调用方法user . doo operation(chio ce,书单);} }公共静态用户log in(){ Scanner Scanner=new Scanner(system。在);System.out.println(请输入用户名:);字符串名称=扫描仪。next line();if (admin ).equals(name)){ system。出去。println(请输入管理员密码:);字符串密码=扫描仪。next line();if (admin ).equals(密码)){ system。出去。println(‘你好!尊敬的管理员!欢迎来到藏经阁);返回新的管理员用户(名称);} else { System.out.println(密码错误,进入用户端!);System.out.println(hello!名称欢迎来到藏经阁);返回新的普通用户(姓名);} } else { system。出去。println(你好!名称欢迎来到藏经阁);返回新的普通用户(姓名);} } }package user

  AdminUser.java

  包com。src 1。图书系统。用户;导入com。src 1。图书系统。操作。*;导入Java。util。扫描仪;公众的类管理员表扩展user { @ Override public int menu(){ Scanner Scanner=new Scanner(system。在);System.out.println(1 .查找图书);System.out.println(2 .新增书籍);System.out.println(3 .删除书籍);System.out.println(4 .书籍列表);System.out.println(0 .退出系统);int chio ce=扫描仪。nextint();返回chioce} public AdminUser(字符串名称){ super(名称);这个。operations=new io operation[]{ new exit operation()、new FindOperation()、new AddOperation()、new DelOperation()、new display operation()};} }规范

  alUser.java

  

package com.src1.booksystem.users;import com.src1.booksystem.operation.*;import java.util.Scanner;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 = scanner.nextInt();        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

  

package com.src1.booksystem.book;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 {    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

  

package com.src1.booksystem.operation;import com.src1.booksystem.book.Book;import com.src1.booksystem.booklist.BookList;import java.util.Scanner;public class AddOperation implements  IOperation{    @Override    public void work(BookList bookList) {        Scanner scanner = new Scanner(System.in);        System.out.println("请输入书名");        String name = scanner.nextLine();        System.out.println("请输入作者");        String author = scanner.nextLine();        System.out.println("请输入价格");        int price = scanner.nextInt();            Book book = new Book(name, author, price);            int curSize = bookList.getUsedSize();            bookList.setBooks(curSize, book);            bookList.setUsedSize(curSize + 1);            System.out.println("新增成功");    }}

BorrowOperation

 

  

package com.src1.booksystem.operation;import com.src1.booksystem.book.Book;import com.src1.booksystem.booklist.BookList;import java.util.Scanner;public class BorrowOperation implements IOperation {    @Override    public void work(BookList bookList) {        System.out.println("借阅书籍");        Scanner scanner = new Scanner(System.in);        System.out.println("请输入你要借阅的图书:");        String name = scanner.nextLine();        for (int i = 0; i < bookList.getUsedSize(); i++) {            Book book = bookList.getBook(i);            if(book.getName().equals(name)) {                if(book.isBorrowed()) {                    System.out.println("此书已经借出了!");                    return;                }                book.setBorrowed(true);                System.out.println("借阅成功!");                return;            }        }        System.out.println("没系统未收录这本书!");    }}

DelOperation

 

  未完善

  

package com.src1.booksystem.operation;import com.src1.booksystem.booklist.BookList;import java.util.Scanner;import com.src1.booksystem.book.Book;public class DelOperation implements IOperation{    @Override    public void work(BookList bookList) {        System.out.println("请输入要删除的书名:");        Scanner scanner = new Scanner(System.in);        String delbook = scanner.nextLine();        int size = bookList.getUsedSize();        for (int i = 0; i < size; i++) {            Book book = bookList.getBook(i);            if(book.getName().equals(delbook)) {                if(i+1<size) {                    bookList.setBooks(i, bookList.getBook(i + 1));                }                bookList.setUsedSize(size-1);                if(i+2 < size) {                    bookList.setBooks(i+1, bookList.getBook(i + 2));                }            }        }        System.out.println("删除成功!");    }}

修改

 

  

public class DelOperation implements IOperation{    @Override    public void work(BookList bookList) {        System.out.println("请输入要删除的书名:");        Scanner scanner = new Scanner(System.in);        String delbook = scanner.nextLine();        int size = bookList.getUsedSize();        int pos = 0;        int i = 0;        for ( i = 0; i < size; i++) {            Book book = bookList.getBook(i);            if(book.getName().equals(delbook)) {                pos = i;                break;            }        }        if(i == size){            System.out.println("系统中没有这本书");            return;        }        for(int j = pos; j < size-1; j++) {            bookList.setBooks(j, bookList.getBook(j + 1));        }        bookList.setUsedSize(size-1);        System.out.println("删除成功!");    }}

DisplayOperation

 

  

import com.src1.booksystem.booklist.BookList;public class DisplayOperation implements IOperation{    @Override    public void work(BookList bookList) {        for (int i = 0; i < bookList.getUsedSize(); i++) {            System.out.println(bookList.getBook(i));        }    }}

ExitOperation

 

  

package com.src1.booksystem.operation;import com.src1.booksystem.booklist.BookList;public class ExitOperation implements IOperation {    @Override    public void work(BookList bookList) {        System.exit(0);    }}

FindOperation

 

  

package com.src1.booksystem.operation;import com.src1.booksystem.book.Book;import com.src1.booksystem.booklist.BookList;import java.util.Scanner;public class FindOperation implements IOperation{    @Override    public void work(BookList bookList) {        Scanner scanner = new Scanner(System.in);        System.out.println("请输入要查找的书名");        String name = scanner.nextLine();        for( int i = 0; i < bookList.getUsedSize(); i++) {            Book book = bookList.getBook(i);            if(book.getName().equals(name)) {                System.out.println(book);                return;            }        }    }}

ReturnOperation

 

  

package com.src1.booksystem.operation;import com.src1.booksystem.book.Book;import com.src1.booksystem.booklist.BookList;import java.util.Scanner;public class ReturnOperation implements IOperation {    @Override    public void work(BookList bookList) {        Scanner scanner = new Scanner(System.in);        System.out.println("请输入你要归还的书名:");        String name = scanner.nextLine();        for (int i = 0; i < bookList.getUsedSize(); i++) {            Book book = bookList.getBook(i);            if(book.getName().equals(name)) {                //说明有这本书                book.setBorrowed(false);                System.out.println("归还成功!");                return;            }        }        System.out.println("系统未找到本书的相关信息!");    }}

接口 IOperation

 

  

package com.src1.booksystem.operation;import com.src1.booksystem.booklist.BookList;public interface IOperation { &      

	  
	  
	  
	  
	  
	  
        

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: