Java代写:FIT9131 My Library

Introduction

用Java基础类实现一个图书馆的小应用,可以借书、还书、管理书等等,属于很基础但是有一定工程量的程序。

Specification

For this assignment you are required to write a program, My Library, that simulates a very small library of electronic books. This section specifies the required functionality of this program.
Even though this program is functionally very different from the program you wrote in Assignment 1, you should be able to re-use much of your previous code here - if you have designed the classes/logic in your previous program properly. This is one of the major benefits of an object-oriented program - the ability to re-use classes.
My Library should provide the following features:

  • maintains a list (using a Java Collection class) of Borrower objects
    • each Borrower object represents a person who is allowed to borrow some books from the library
  • maintains a fixed list of exactly 10 books
    • each book is implemented using a String, which consists of the book’s title and the author
    • each book can be borrowed by different borrowers at the same time
  • (HD level) maintains a fixed list of unlimited Book objects
    • each Book object represents a single (electronic) book which can be borrowed by different borrowers at the same time
    • a book has a rating (children/adult), which limits its availability to a borrower based on his age
  • allows each borrower to borrow up to 2 books at any one time
  • lists the details of an existing borrower and the books he has currently borrowed
  • produces a report of all borrowers
  • allows a borrower to borrow/return a book
  • loads a list of borrowers from a text file
    • a sample data file will be provided to you – your program must be able to read the data from this file
  • (HD level) loads a list of books from a text file
    • a sample data file will be provided to you – your program must be able to read the data from this file
    • saves the list of current borrowers (with the borrowed books) to a text file

You are to demonstrate the following programming techniques in your program:

  • reading/writing data from/to text files
  • using appropriate Java Collection class or classes to store data
  • using code to manipulate the data in the collection(s)
  • performing simple searches, filtered by some given criteria
  • using program constructs such as repetitions & selections
  • using appropriate classes to represent the various objects in the program

There will be a description of the “HD level” features later in this document.
You are also required to produce a partial Test Strategy for your program.

Program Logic

When the program starts, it should automatically load a text file called “borrowers.txt” which contains details of all borrowers currently stored in the system. The actual format of this text file is described later in this document. The data loaded should be stored in some appropriate data structures. No other reading from (or writing to) file is required while the program is in operation, until the user chooses to exit, at which point the program saves all the in-memory data back to the same text file (borrowers.txt).
In other words, all the file I/O operations are performed automatically by the program, once at the start and once at the end, and require no interactions with the user.
When the program is running, it should repeatedly display a menu with at these options (non-HD level), such as:

Welcome to the My Library
====================
(1) Register New Borrower
(2) Manage Borrower
(3) List All Borrowers
(4) Display Help
(5) Exit Library
Choose an option:
  • Option (1) registers a new borrower. Information to be entered will be a name, a unique ID, and an age.
  • Option (2) manages an existing borrower. The borrower is to be searched for by some sensible criteria. A second menu will allow the following operations for that borrower:
    • (2.1) borrow a book
    • (2.2) return a book
    • (2.3) list borrowed books
  • Option (3) lists all the current borrowers (& their borrowed books)
  • Option (4) displays some sensible help screen to explain how the program works.
  • Option (5) exits the program. All the borrowers’ data currently in memory are automatically saved to “borrowers.txt”. The memory is then cleared.

Inputs other than 1-5 should be rejected, and an error message printed. The menu should be displayed repeatedly, until the user chooses Option (5).

Important Requirements

You must observe the following requirements when implementing your program:

  • a Borrower object remembers the following data:
    • name: a String
    • must not be blank
    • does not need to be unique
    • ID: an int
    • must be unique, and between 1-100 (inclusive)
    • age: an int
    • must be > 5 and <= 110
    • booklist: a String (non-HD level), or a list of Book objects (HD level)
  • for each book, there are 2 ways of implementations:
    • non-HD level: a String containing the book title (String) + author (String), separated by a comma (eg. “Learn Java in 3 Minutes, David Smith”)
    • HD level: a Book object with the following data:
    • title: a non-empty String
    • auther: a non-empty String
    • rating: a non-empty String (valid values are “Children” or “Adult”)
  • (HD level) only borrowers who are more than 18 years old are allowed to borrow books with an “Adult” rating.
  • you may assume that the input data file is always in the correct format (see below) - ie. no need to validate the data when reading it in.
  • all operations must be applied to the in-memory data, or data structures - there must not be constant reading/writing to/from the data file, except once at the start (when the program loads all data from the file) and once at the end (when the program saves all data back to the file, when it exits)
  • the program must not crash when accepting user inputs, regardless of what the user enters.

Input File Format

The input data file (borrowers.txt) has the following format for each line:

name,ID,age,title1,auther1,title2,auther2

Eg. the following sample data file contains 3 borrowers:

David Smith,1,19,Book of Java,John Wilson,ABC of Life,Arnold S
John Williams,2,12,ABC of Life,Arnold Bolton,Network Security,Jeremy Hacker
Sue Dally,3,55,How to use a Computer,David Noidea

Each line represents a single “borrower”. The fields are separated by commas. Each “book” takes up 2 fields.
For the HD level, each “book” will have an additional field (the rating).

Program Design

Your program must demonstrate your understanding of the object-oriented concepts and general programming constructs presented in FIT9131. You must use appropriate data structures to store the various objects (list of borrowers, list of books (HD-level), etc) in the program.
You must be able to justify the choice of the data structures during your interview. You must document any additional assumptions you made.
Appropriate validations of values for fields and local variables should also be implemented. You should not allow an object of a class to be initialized/set to an invalid state.
Discuss with your tutor what classes are appropriate, and how they interact with each other. The main requirements are: (1) the borrowers (and for the HD level, the books) must be implemented as objects, and they must be stored in some appropriate Java collections, and (2) the list of books within each borrower object must also be stored in some appropriate Java collections.
Your program must deal with invalid values entered by the user in a sensible manner. For instance, if a user enters “abc” when a number is expected, your program should not crash.
All on-screen input/output should be formatted in a user-friendly manner. Sensible error messages should be displayed whenever appropriate (eg. entering a duplicate borrower ID, entering a number outside the allowable valid range, etc).

Test Strategy

For this assignment, you are required to produce and submit a partial Test Strategy for the program.
Your Test Strategy will be only for one class - the Borrower class.
There is no need to produce Test Strategy for any other classes you have used in your program.
You must provide a Test Plan, plus detailed sets of Test Data, Expected Results and Actual Results for the Borrower class.