Java图书馆借阅功能实现

某镇上有两个图书馆,请按照下面要求及提示帮助这两个图书馆实现图书电子借阅。

完成Library.java,该类中的main()方法已经给出。但类成员和类方法需要完善。完成该类的时候请注意以下要求:

 A.该类中有类成员方法,也有实例成员方法;

 B. 不能改变main()方法的内容。

 C.main( )方法的输出为:

   Library hours:

   Libraries are open daily from 9am to 5pm.

   Library addresses:

   10 Main St.

   228 Liberty St.

  Borrowing The Lord of the Rings:

  You successfully borrowed The Lord of the Rings

  Sorry, this book is already borrowed.

  Sorry, this book is not in our catalog.

 Books available in the first library:

 The Da Vinci Code

 Le Petit Prince

 A Tale of Two Cities

Books available in the second library:

No book in catalog

Returning The Lord of the Rings:

You successfully returned The Lord of the Rings

Books available in the first library:

The Da Vinci Code

Le Petit Prince

A Tale of Two Cities

The Lord of the Rings

import java.util.ArrayList;

/**
 * @version 1.0
 */

public class Library {
    // Add the missing implementation to this class
    String Library_title;

    public static class Book {

        String title;
        boolean borrowed;

        public Book(String title) {
            this.title = title;
            borrowed = false;
        }
    }

    //Book[] books = new Book[6];
    ArrayList<Book> books= new ArrayList<>();

    public Library(String library_title) {
        Library_title = library_title;
       // books = new Book[6];
    }

    public void addBook(Book book) {
//        Book_num++;
//        books[Book_num].title = book.title;
//        books[Book_num].borrowed = book.borrowed;
        books.add(book);
    }

    public static void printOpeningHours() {
        System.out.println("Libraries are open daily from 9am to 5pm.");
    }

    public void printAddress() {
        System.out.println(Library_title);
    }

    public void borrowBook(String name) {
        int i;
        for (i = 0; i < books.size(); i++) {
            if (name.equals(books.get(i).title)) {
                break;
            }
        }
        if (i == books.size()) {
            System.out.println("Sorry, this book is not in our catalog.");
        } else {
            if (!books.get(i).borrowed) {
                System.out.println("You successfully borrowed The Lord of the Rings");
                books.get(i).borrowed = true;
            } else {
                System.out.println("Sorry, this book is already borrowed.");
            }
        }
    }

    public void printAvailableBooks(){
        int i,j=0;
        for(i=0;i<books.size();i++){
            if(!books.get(i).borrowed){
                System.out.println(books.get(i).title);
                j++;
            }
        }
        if(j==0){
            System.out.println("No book in catalog");
        }
    }
    public void returnBook(String name){
        int i;
        for (i = 0; i < books.size(); i++) {
            if (name.equals(books.get(i).title)) {
                break;
            }
        }
        if (i == books.size()) {
            System.out.println("Sorry, this book is not in our catalog.");
        } else {
                System.out.println("You successfully returned "+name);
                books.get(i).borrowed = false;
        }
    }


    public static void main(String[] args) {
        // Create two libraries
        Library firstLibrary = new Library("10 Main St.");
        Library secondLibrary = new Library("228 Liberty St.");

        // Add four books to the first library
        firstLibrary.addBook(new Book("The Da Vinci Code"));
        firstLibrary.addBook(new Book("Le Petit Prince"));
        firstLibrary.addBook(new Book("A Tale of Two Cities"));
        firstLibrary.addBook(new Book("The Lord of the Rings"));

        // Print opening hours and the addresses
        System.out.println("Library hours:");
        printOpeningHours();
        System.out.println();

        System.out.println("Library addresses:");
        firstLibrary.printAddress();
        secondLibrary.printAddress();
        System.out.println();

        // Try to borrow The Lords of the Rings from both libraries
        System.out.println("Borrowing The Lord of the Rings:");
        firstLibrary.borrowBook("The Lord of the Rings");
        firstLibrary.borrowBook("The Lord of the Rings");
        secondLibrary.borrowBook("The Lord of the Rings");
        System.out.println();

        // Print the titles of all available books from both libraries
        System.out.println("Books available in the first library:");
        firstLibrary.printAvailableBooks();
        System.out.println();
        System.out.println("Books available in the second library:");
        secondLibrary.printAvailableBooks();
        System.out.println();

        // Return The Lords of the Rings to the first library
        System.out.println("Returning The Lord of the Rings:");
        firstLibrary.returnBook("The Lord of the Rings");
        System.out.println();

        // Print the titles of available from the first library
        System.out.println("Books available in the first library:");
        firstLibrary.printAvailableBooks();
    }
}

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
2.1 可行性分析 采用现代化统一的计算机信息网站系统,能够有效优化图书馆管理系统,使其高效的发挥最大作用,能够迅捷的为读者提供相应的服务。开发本系统的可行性研究如下: 2.1.1 技术可行性 技术上的可行性分析主要分析技术条件能否顺利完成开发工作,软、硬件能否满足需要。本系统采用JSP开发出友好美观的人机界面,便于用户理解、操作。数据库管理系统采用MySQL,它能够处理大量数据,同时保持数据的完整性、安全性。因此本系统的开发平台已成熟可行。硬件方面,在科技飞速发展的今天,硬件更新速度越来越快,容量越来越大,可靠性越来越高,价格越来越便宜,因此硬件平台也能够满足本系统所需。 2.1.2 经济可行性 鉴于计算机技术发展异常迅猛,在硬件软件配置以及开发技术均以可行的情况下开发这样一个管理系统成本不会很高,但其可以大大提高图书馆的工作效率,也是图书馆管理发展的必然趋势,其必将有比较宽阔的市场,因此改性统在经济可行性上时可行的。 2.2 图书借阅管理系统需求概述 2.2.1 系统目标 该系统主要建立一个基于B/S模式的图书馆借阅管理系统,面对当起很多小型图书管理仍是人工管理带来的检索速度慢,效率低,借阅归还图书量大,图书统计工作量大,藏书不能完成及时更新的问题,该系统可以对跟系统的三个用户类型的使用实现: (1)对于读者在本系统的应用下可实现按照各种方式(如:书名,编号,作者)查询图书馆的藏书请客,方便的借阅图书,续借图书,归还图书,能够查询自己的借阅图书情况。 (2)对于图书馆工作人员能够实现方便的对图书进行查询,方便的进行读者借阅情况查询,方便的进行借书还书处理等,便捷的对图书信息进行添加、修改、删除,分类管理等操作,对读者信息进行相关添加,修改,分类管理等操作。 (3)对于系统管理员可以对图书馆信息进行修改更新操作,对系统用户进行添加、修改、删除、权限设置等操作,对图书馆的办证参数进行修改维护等操作功能。 2.2.2 用户类和用户特性 图书借阅管理系统是一个基于B/S模式的对图书馆进行高效率管理的应用系统,它的用户主要是读者和图书管理员,图书管理员通过本系统实现对图书及读者的高效管理,除此之外,还需要一个系统管理员对不同的用户进行权限的设置等操作。 三类用户的具体描述如表2.1所示。 表2.1用户具体描述

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

呆呆水獭_(:_」∠)_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值