159.234

159.234-2021 Semester 1
1
Assignment 2
Deadline: Thursday 6 May, 11 PM
Evaluation: 40 marks – which represents 20% of your final grade
Late Submission: 5 marks off per day late
Teams: The assignment can be done individually or in teams of two people (one
assignment per team submitted including both student names in the source code).
Purpose: Practice programming with OOP core concepts using Java

  1. Problem to solve:
    You are asked to write a program to be used by Massey University Library. There are three types of items that
    can be borrowed from the library – Books, Journals and Movies. The library keeps records of each item’s
    type, id, title, year, average rating, number of reviews, and max number of days for borrowing (28 days
    for books, 14 days for journals, and 7 days for movies). If an item is on loan, its due date should also be
    recorded. Other information you should record: author and number of pages for books, director for movies,
    and volume and number for journals.
  2. Tasks: Your program should
    A. Read text file library.txt; for each line in the file create a Movie/Book/Journal object and add the
    object to the library object.
    B. Output all items in the library
    C. Prompt questions to allow users to do the following (see attached output for more details):
    a. Search items by id or phrase in title, and list the items found
    b. Select an item from the listed items of a search result and display its details
    c. Borrow the selected item if it is available, and display new due date, or
    d. Return the selected item if it is on loan, or
    e. Rate the selected item, and display new average rating
    Functions workflow (related tasks are marked as A, B, C-a, C-b, C-d, C-d, and C-e):
    Run your program
    Create and add library items to your system (A) and output all the items (B)
    quit or search by ‘id’ or ‘phrase in title’ (C-a)
    quit
    enter ‘id’
    Display selected item details (C-b)
    borrow or rate the item (C-c, C-e)
    return or rate the item (C-d, C-e)
    if item is available if item is on loan
    Display item details after borrowed or rated
    (C-c, C-e)
    borrow rate, enter rate value
    Display item details after returned or rated
    (C-d, C-e)
    return rate, enter rate value
    restart restart
    restart restart
    Display the matching item(C-a)
    Selected the item
    title’
    enter ‘phrase in title’
    Display all the matching items(C-a)
    Selected one of the displayed items
    title’
    restart
    restart
    Restart
    search by
    ‘title’
    Restart
    search
    by ‘id’
    159.234-2021 Semester 1
    2
  3. Design and Implementation Guideline
    Note: The following OOP and general software design concepts will be checked while marking the program
    1) Class design and implementation
    b. data fields – internal data not accessed by external classes
    c. methods
    d. constructors
    2) Encapsulation design and implementation – proper use of modifiers
    a. private
    b. protected
    c. public
    3) Inheritance design and implementation
    a. Reasonable class hierarchies
    b. Proper data fields separation in base and derived classes
    c. Proper methods separation/overloading/overriding in bass and derived classes
    d. Proper use of base and derived class constructors
    4) Polymorphism and implementation
    a. Write generic code that targets the base class whenever possible
    b. Appropriate use of overriding in derived classes to realize polymorphism
    5) Information store and implementation
    a. Use ArrayList or other Java collection class to store information.
    b. Must make use of getters and/or setters wherever appropriate.
    6) Exception handling
    a. Throw an exception object when an application error occurs (For example, an invalid piece of data is
    entered)
    b. Using “try/catch/finally” or “try/catch” block to handle the exception
    3
    159.234-2021 Semester 1
  4. You must follow the next three specifications in each and every assignment for this course
    1) Place the following comments at the top of your program code and provide the appropriate
    information:
    // Family Name, Given Name, Student ID, Assignment number, 159.234
    / explain what the program is doing . . . /
    2) Create the function displayInfo and provide the appropriate information as shown below:
    The displayInfo should be the first thing that you display on the screen.
    3) DO NOT use any function to clean the screen at any stage of a program, for any assignment in this
    course.
  5. Hand-in: Submit all your .java file as a2.zip electronically on the course stream site.
    Marks will be allocated for: correctness, completeness, no code duplication, applying OOP core concepts appropriately,
    documentation, clear on screen output display…
  6. Output of a sample solution
    Task A: Add the test data (see library.txt file) into your system.
    This is the content of the provided library.txt for test purpose.
    Record of movie:
    Type, Id, title,
    year, director
    Record of book: Type,
    Id, title, year, author,
    number of pages
    Record of journal:
    Type, Id, title, year,
    volume, number
    4
    159.234-2021 Semester 1
    Task B output: all the items in the library:

The initial value of ‘Average rating’
should be set to 0.0 for all items –
no rating at the beginning
The initial value of ‘Number of
reviewers’ should be set to 0 for
all items – no reviewer at the
beginning
The initial value of ‘Status’
should be set to ‘available’ for
all items – not on loan yet
First, Output all
items’ details one
by one
The initial value of ‘Average rating’
should be set to 0.0 for all items –
no rating at the beginning
The initial value of ‘Number of
reviewers’ should be set to 0 for
all items – no reviewer at the
beginning
The initial value of ‘Status’
should be set to ‘available’ for
all items – not on loan yet
First, Output all
items’ details one
by one
5
159.234-2021 Semester 1

6
159.234-2021 Semester 1
After you output all items, prompt these options to
allow the user to choose a search method
7
159.234-2021 Semester 1
Task C: Prompt questions to allow the user to select all the functions:
If ‘b’ is entered, previous
options will be prompted
8
159.234-2021 Semester 1
The item’s status changed to ‘on
loan’ after being borrowed
Due date is current date + max number of
days for borrowing.
To calculate data in Java, you may use java
library java.util.Calendar,
java.text.SimpleDateFormat, etc.
Only one rating is available so the user
entered rating value (8 in this example) equal
to the ‘Average rating’
‘Number of reviewers’ changed
from 0 to 1 after the first rating
9
159.234-2021 Semester 1
Multiple rating for one item is allowed from one
user, so after the second rating, the ‘Average
rating’ is: (8+6)/2=7
‘Status’ becomes ‘available’
after the item is returned
‘Number of reviewers’ changed from 1 to
2 after the second rating
10
159.234-2021 Semester 1
There are two items whose titles
include ‘Lord’ – see number ‘*1’
and number ‘*2’

你可能感兴趣的:(后端)