159.234 OBJECT-ORIENTED PROGRAMMING S1, 2023
Assignment 2
Deadline: 11 May 2023, 11pm
Evaluation: 40 marks (15% of your final grade)
Late Submission: Deduct 5 marks per day late
Individual Work You must complete this assignment by yourself (you must NOT share your code
with others or use others’code including the code generated by Artificial
Intelligence platforms such as ChatGPT)
Purpose: Reinforce Java OOP core concepts (abstraction, encapsulation, inheritance, and
polymorphism), collections framework and generics, exception handling, and
input and output streams.
- System Description (Overview of Problem)
You are asked to write a program in Java to simulate a University Library System
Three types of items can be borrowed from the library—Books, Journals, and Movies. The library records
each item’s type, ID, title, year, average rating, number of reviews, and maximum borrowing time (28
days for Books, 14 days for Journals, and 7 days for Movies). Furthermore, for books, the library must
record author and number of pages; for movies, it must record director; and for journals, it must record
volume and number. Due dates must be recorded for all items out on loan. - Programming tasks to complete:
A. Read text file library.txt (supplied); for each line in this file, create a Movie/Book/Journal object and add
it to your‘library’object
B. List all items in the library, but only display its ID, type, and title
C. Prompt questions to allow users to do the following (refer to attached sample output at the end of this
document for expected prompts and display details):
a. Sort all the items first by average rating and then by ID
b. Search items by ID or phrase in title, and list the items found
c. Select an item from search results and display its details
d. Borrow the selected item if it is available, and display new due date, or
e. Return the selected item if it is on loan, or
f. 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, C-e, and C-f):
Run your program
Create and add library items to your system (A) and output all the items (B)
Search by‘id’or‘phrase in title’(C-b)
quit
enter‘id’
Display selected item details (C-c)
Borrow or rate the item (C-d, C-f) Return or rate the item (C-e, C-f)
if item is available if item is on loan
Display item details after borrowed or rated
(C-d, C-f)
borrow rate, enter rate value
Display item details after returned or rated
(C-e, C-f)
return rate, enter rate value
restart
restart
restart restart
List the matching item (C-b)
Selected the item
title’
enter‘phrase in title’
List all the matching items (C-b)
Selected one of the displayed items
title’
restart
restart
Restart
search by
‘title’
Restart
search
by‘id’
Sort all the
items (first by
average rating
and then by id)
(C-a)
quit
2
159.234 OBJECT-ORIENTED PROGRAMMING S1, 2023 - Design and Implementation Guidelines
Note: You will receive credit for correctness, completeness, no code duplication, and clear on-screen outputs.
Also, the following OOP and general software development guidelines will be checked while marking
your program:
1) Encapsulation design and implementation—proper use of modifiers
a. Private/Protected/Public
b. Must make use of getters and setters wherever appropriate.
2) 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 base and derived classes
d. Proper use of base and derived class constructors
3) 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
4) Collections framework and generics
a. Use ArrayList or another Java collection class to store information
b. Implement Comparable/Comparator Interface(s) to sort items
5) Exception handling
a. Throw exceptions when an error occurs (e.g., an invalid piece of data is entered)
b. Use“try/catch/finally”or“try/catch”block to handle exceptions - Other Specifications
You must follow the next five specifications when completing this assignment:
1) Create the method displayInfo to provide appropriate information as shown below.
The content of displayInfo should be the first thing that displays onscreen
2) Place appropriate comments in your program – e.g.:
/* explain what the program file is doing . . . /
// explain what a part/method of the program is doing…
3) DO NOT add any file path for‘library.txt’(put it directly in your project folder when you test your
code)
4) DO NOT add your own package name(s) to the beginning of your .java file
5) DO NOT use any function to clean the screen at any stage of your program
3
159.234 OBJECT-ORIENTED PROGRAMMING S1, 2023 - Submission Requirements:
1) Zip all your source code (.java files) and submit as a single zip file to Stream - Test data and sample outputs: