Java代写:CSC216 Wolf Library Part1

Introduction

代写一个Java项目应用,开发过程中需要体现出完整的软件开发流程,包括设计、实现、测试等等,并且体现工作量。设计和实现,需要根据Use Case的需求。

Requirement

This project requires you to go through standard software development phases to design, implement, and test a complete Java program consisting at multiple source code files and JUnit test cases. Part 1 of Project 2 focuses on design and system tests for the project’s requirements. There are two deliverables for Part 1:

  1. Design proposal and rationale that includes a UML class diagram.
  2. Black box test plan.

Problem overview

Many people enjoy the convenience of eReaders like Kindles, Nooks, and iPads. But almost all of us still like the feel of books with paper rather than virtual pages. That makes us potential patrons of a new interactive book lending library system called WolfLibrary, which lends only physical books on real paper. Although it has not yet come close to amassing a credible book inventory, WolfLibrary is starting to catch the interest of venture capitalists.
WolfLibrary provides an interactive system that library patrons use to view the book inventory and select books that they are interested in, putting them into their reserve queues for eventual check out. Whenever the patron returns a checked out book, WolfLibrary automatically checks out the next available book in the patron’s reserve queue, shipping it directly to the patron. Patrons can have between 1 and 5 books checked out at a given time, depending on their account settings.
You must write a prototype for a lending library system that WolfLibrary can demonstrate to venture capitalists. The prototype system will include an administrator, patrons, and an inventory of books.

The book inventory

There is a (theoretically) unlimited number of books in the WolfLibrary inventory. Each book is identified by its title and author. There may be multiple copies of each book. Some books are in stock and ready for shipment. Others are checked out by patrons.
Information on the library book inventory is loaded from a text file on program startup. The file consists of lines representing books, where each line follows this format:

<number­-in­-stock><whitespace><book-­info>

Here, number­-in-­stock is an integer and book­-info is the book title followed by the author. An example library file might look like this:

3  Pride and Prejudice by Jane Austin
5     D Day: June 6, 1944: The Climactic Battle of World War II by Stephen E. Ambrose
1    Love in the Time of Cholera by Gabriel Garcia Marquez
0 The Elements of Style (4th Edition) by Strunk and White

For that short sample file above, there is currently only one copy in stock of “Love in the Time of Cholera.” There are no copies in stock of “The Elements of Style,” which indicates that all copies are currently checked out.

The administrator

There is a single administrator for the entire system. The administrator can login to the library system, create new patron accounts, cancel accounts, logout, and shut the system down. The administrator’s username is admin and password is also admin.

The patrons

The prototype system can have up to 20 patrons. Patrons can login, logout, browse the book inventory, put books in their reserve queues, rearrange or remove books from their reserve queues, and return books that they have checked out.

The user interface

Users access the system via a graphical user interface. The GUI has four faces that correspond to user actions:

  1. Login face. For logging into the system. This face is shown at startup and whenever a user logs out of the system.
  2. Welcome face. Opens as soon as a user logs in. The face has buttons according to who is logged in:
    • Admin logged in: There are buttons for adding a new patron account and canceling an account. The Logout and Quit buttons at the bottom are enabled.
    • Patron logged in: There are Browse and Queue buttons at the top for browsing the inventory and working with books checked out and the reserve queue. The Logout button at the bottom is enabled; the Quit button is not.
    • The library system supports only a single user at a time. (No user can log in while another user is already logged in.)
  3. Browse face. For viewing the books in the library and selecting ones to go into reserve queues. This face is open only to patrons.
  4. Queue face. For viewing reserve queues and collections of books checked out, rearranging and removing books from the reserve queues, and returning checked out books to the library. This face is also open only to patrons.

Buttons at the top of the application window vary according to who is logged in. The Quit button at the bottom is enabled whenever the the administrator is logged in.

Requirements use cases

Use cases are described here according to the faces on the GUI.

Login services and startup

Use Case 1: Startup

Preconditions: The user starts the program.
Main Flow: The user starts the program either with a command­line argument [S1] or a file chooser [S2] for the name of the file that has inventory information. The program builds the inventory from the file [S3] and opens the Login face [S4], as illustrated on the right. Buttons for administrative actions and patron actions are initially disabled.
Subflows:

  • [S1] The user specifies the file as a command­line argument [S3][E1].
  • [S2] If there is no command­line argument, the program displays a file chooser for file selection [E1].
  • [S3] An inventory of books is created by processing each line of the file as described above [E2].
  • [S4] The Login face opens with all buttons except Login disabled.

Alternative Flows:

  • [E1] If the filename specified by the user does not exist or if the user cancels the file chooser, the program exits.
  • [E2] Any defective line in the file specified by the user is ignored.

Use Case 2: Login

Preconditions: The program is running, the Login face is open and the Login button is enabled. All other buttons are disabled.
Main Flow: The user enters information for the username and password fields then clicks Login. The
user is logged into the system [S1] and the main window shows the Welcome face [S2][S3].
Subflows:

  • [S1] The username/password combination is verified [S1][S2][E1].
  • [S2] If the username/password matches the administrator’s username and password (admin/admin), the administrator is logged in. The Welcome face shows the enabled buttons of Add New Patron Account, Cancel Account, Quit, and Logout.
  • [S3] If the username/password matches a patron in the patron database, the patron is logged in. The Welcome face shows the buttons Browse, Show My Books, Logout, and Quit. The Quit button is disabled.

Alternative Flows:

  • [E1] The username/password pair entered by the user does not correspond to the administrator or to any patron. The system displays a dialog with the message “Account information is incorrect.”, shown below, and the user is not logged in. Buttons remain in their current enabled/disabled states.

Use Case 3: Logout

Preconditions: A user (patron or administrator) is logged in [UC2]. Any face can be open but there are no open dialog boxes.
Main Flow: The user clicks Logout [S1]. The Login face opens [S2] and the user is logged out [S3].
Subflows:

  • [S1] The user who is logged in is automatically logged out.
  • [S2] The Login face opens.
  • [S3] The Login button is enabled. All other buttons are disabled.

Use Case 4: Quit

Preconditions: The administrator is logged in [UC2]. The admin Welcome face is open but there are no open dialogs.
Main Flow: The administrator stops program execution [S1][S2].
Subflows:

  • [S1] The administrator clicks Quit.
  • [S2] The program stops execution without any errors.

Administrator Functionality

Use Case 5: Add new account

Preconditions: The administrator is logged in [UC2][S2]. The admin Welcome face is open but there are no open dialogs.
Main Flow: The administrator clicks Add New Patron Account. A dialog box opens for entering new patron information as shown below. The administrator enters the new username and password and selects how many books this patron can have checked out [S1][S2] or the administrator cancels the action [E4].

  • [S1] The username/password combination is checked against the current database to make sure it is valid [E1][E2] and does not match user already in the database [E3].
  • [S2] The new patron is added to the database, which maintains its list of users in case­ insensitive alphabetic order by user name.

Alternative Flows:

  • [E1] The patron database is full. A dialog box opens with the message “There is no room for additional patrons.” indicating the database has no room for additional accounts as shown below. The administrator clicks OK, and all dialog boxes close. The patron database remains unchanged.
  • [E2] The username or password are all whitespace, empty, or contain embedded whitespace characters. A dialog box opens with the messsage “Id and password may not contain whitespace.” indicating the username or password are not valid as shown below. This patron is not added to the database. The administrator clicks OK, and the dialog boxes close. The patron database remains unchanged.
  • [E3] The username matches one already in the database. A dialog box opens with the message “Patron already has an account.” indicating the patron already has an account as shown below. The administrator clicks OK, and all dialog boxes close. The patron database remains unchanged.
  • [E4] The administrator clicks Cancel in the New UserName and Password dialog. The dialog closes and the patron database remains unchanged.

Use Case 6: Cancel account

Preconditions: The administrator is logged in [UC2][S2]. The admin Welcome face is open but there are no open dialogs.
Main Flow: The administrator clicks Cancel Account. A dialog box opens as shown below. The administrator enters the username for the account to cancel and clicks OK [S1] to delete the associated patron’s account and close the dialog or Cancel to stop the action [E1].
Subflows:

  • [S1] The specified account is removed from the patron database [E2]. The remaining items in the patron database remain in order by username.
  • [S2] All books that the patron with the specific account has checked out are returned to the library inventory.

Alternative Flows:

  • [E1] The administrator clicks Cancel. The patron database remains unchanged.
  • [E2] The username entered does not match any patron in the database. A dialog opens with the message “Account information in incorrect.” to indicate the error as shown below. The administrator clicks OK, and all dialog boxes close. The patron database remains unchanged.

Browse

Use Case 7: Navigate to the Browse face

Preconditions: A patron is logged in [UC2].
Main Flow: The user (patron) clicks Browse. The Browse face opens, showing all books in the inventory in a scrollable list, as shown on the right [S1][S2].
Subflows:

  • [S1] Each book is displayed in the list by its title and author only. If all copies for that book are currently out of stock, the book is shown with an asterisk and blank (“* “) before its title and author. See Christine by Steven King in the snapshot to the right.
  • [S2] The books are listed in alphabetical order according to their info (title and author). The ordering is not case sensitive, and it ignores any initial articles “The”, “A”, and “An”.

Use Case 8: Reserve the selected book

Preconditions: A patron is logged in [UC2] and has opened the Browse face [UC7].
Main Flow: The user (patron) selects a book from the list and clicks Reserve Selected Book [E1] to check out the book [S1] or put it in the reserve queue if the maximum number of books is already checked out [S2].
Subflows:

  • [S1] If a copy of the book is available and if the user has fewer than the maximum allowable number of books checked out (according to the user’s account settings)
    • [S3]: The selected book is added to the end of the list of books that the user checked out. (Hence a copy of the book would be mailed to the user.)
    • The number of copies of that book in the library is decremented by 1.
  • [S2] If the selected book is not available or if the user has the maximum allowable number of books checked out, the selected book is added to the end of the user’s reserve queue [S3]. This does not decrement the number of books in the library.
  • [S3] The selected book is shown as reserved on the bottom of the window. The books on the Library Inventory list are updated as needed.

Alternate Flows:

  • [E1] The user fails to select a book but clicks Reserve Selected Book. Nothing happens.

Queue management

Important: There is no restriction on queue duplicates ­­ patrons can have multiple copies of the same book both checked out and in their reserve queues.

Use Case 9: Navigate to Queue face

Preconditions: A patron is logged in [UC2].
Main Flow: The user clicks Show My Books at the top of the window. The Queue face opens showing the user’s reserve queue [S1] and list of books that the user has checked out [S2][E1].
Subflows:

  • [S1] The queue face shows the user’s reserve queue under My Reserve Queue. The books are displayed according to the order they were placed in the list and (possibly) subsequently moved.
  • [S2] The books in My Checked Out Books shows all books that the user currently has checked out, listed in the order in which they were checked out.

The snapshot at the right shows the Queue face for a patron who has an upper limit of 3 books checked out. Notice that the books are shown strictly by title and author. There is no indication of whether copies for a particular book are out of stock in the inventory.

Use Case 10: Return a book to the library’s inventory

Preconditions: A patron is logged in [UC2]. The Queue face is open [UC9].
Main Flow: The user selects a book in My Checked Out Books then clicks Return Selected Book [S1][E1].
Subflows:

  • [S1] The selected book is removed from My Checked Out Books [S2].
  • [S2] The number of copies of that book in the library inventory is incremented by 1 [S3].
  • [S3] The available book closest to the front of My Reserve Queue is moved from there to the bottom of My Checked Out Books [S4][E2].
  • [S4] The number of copies of the book from [S3] is decremented in the library by 1.
  • [S5] The Queue face shows the updated lists.

Alternate Flows:

  • [E1] The user fails to select a book and clicks Return Selected Book. Nothing happens.
  • [E2] If there are no available books in the reserve queue following [S3], then there are no subsequent changes to any lists.

Use Case 11: Remove a book from the reserve queue

Preconditions: A patron is logged in [UC2]. The Queue face is open [UC10].
Main Flow: The user selects a book in the My Reserve Queue then clicks Remove Selected Book [S1][E1].
Subflows:

  • [S1] The selected book is removed from My Reserve Queue [S2].
  • [S2] The Queue face shows the updated lists.

Alternate Flows:

  • [E1] The user fails to select a book and clicks Remove Selected Book. Nothing happens.

Use Case 12: Move the selected book in the reserve queue up one position.

Preconditions: A patron is logged in [UC2]. The Queue face is open [UC10].
Main Flow: The user selects a book in My Reserve Queue then clicks Move Selected Book Up [S1][E1].
Subflows:

  • [S1] The selected book is moved up one position in My Reserve Queue[S2].
  • [S2] The Queue face shows the re­ordered list.

Alternate Flows:

  • [E1] The user fails to select a book and clicks Move Selected Book Up. Nothing happens.

Design

For Part 1 of this assignment, you must create a design proposal containing a design rationale and a UML class diagram.
Your design must:

  • utilize the Model­View­Controller (MVC) design pattern
  • contain a GUI (no need to show all its members)
  • contain at least one interface
  • contain at least one composition relationship

You should answer the following technical questions in your design document as part of the rationale:

  1. Have you identified the objects important to the system’s implementation and how do you know they are important?
  2. Have you identified all data required to implement the system and how do you know these data are needed?
  3. Are the responsibilities assigned to an object appropriate for that object’s abstraction and why?
  4. Have you identified the relationships between objects (i.e. inheritance or composition) and described why those relationships are important?
  5. Have you identified any design patterns appropriate for implementing the system? How are the identified patterns appropriate for implementing the system?
  6. What are the limitations of your design? What are the constraints of your system?

When thinking about the relationships between your UI and the model, consider these questions:

  1. What are the data and behaviors of your model that will be shown through the UI?
  2. How does your UI get those data to display; what methods of the model must be called?