159.234 OBJECT-ORIENTED PROGRAMMING S1, 2022 |
Assignment 2
Deadline: | 12 May 2022, 11pm |
Evaluation: | 40 marks (20% 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) |
Purpose: | Reinforce Java OOP core concepts (abstraction, encapsulation, inheritance, and polymorphism), collections framework and generics, exception handling, input and output streams, and unit testing |
- 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:
- 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
- List all items in the library, but only display its ID, type, and title
- 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):
- Sort all the items first by average rating and then by ID
- Search items by ID or phrase in title, and list the items found
- Select an item from search results and display its details
- Borrow the selected item if it is available, and display new due date, or
- Return the selected item if it is on loan, or
- Rate the selected item and display new average rating
- Write JUnit test cases to check if your ‘search items by ID or phrase in title’ methods return correct results
- Functions workflow (related tasks are marked as A, B, C-a, C-b, C-d, C-d, C-e, and C-f):
quit |
quit |
Create and add library items to your system (A) and output all the items (B) |
enter ‘id’ |
enter ‘phrase in title’ Restart search by ‘title’ |
List the matching item (C-b) List all the matching items (C-b) |
Selected the item |
Selected one of the displayed items |
restart |
Display selected item details (C-c) |
restart |
if item is available |
if item is on loan |
restart |
restart |
Borrow or rate the item (C-d, C-f) |
Return or rate the item (C-e, C-f) |
restart |
borrow |
rate, enter rate value |
return |
rate, enter rate value |
restart |
Display item details after returned or rated (C-e, C-f) |
Display item details after borrowed or rated (C-d, C-f) |
Search by ‘id’ or ‘phrase in title’ (C-b) |
Restart search by ‘id’ |
Sort all the items (first by average rating and then by id) (C-a) |
Run your program |
159.234 OBJECT-ORIENTED PROGRAMMING S1, 2022 |
- 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:
- Encapsulation design and implementation—proper use of modifiers
- Private/Protected/Public
- Must make use of getters and setters wherever appropriate.
- Inheritance design and implementation
- Reasonable class hierarchies
- Proper data-fields separation in base and derived classes
- Proper methods separation/overloading/overriding in base and derived classes
- Proper use of base and derived class constructors
- Polymorphism and implementation
- Write generic code that targets the base class whenever possible
- Appropriate use of overriding in derived classes to realize polymorphism
- Collections framework and generics
- Use ArrayList or another Java collection class to store information
- Implement Comparable/Comparator Interface(s) to sort items
- Exception handling
- Throw exceptions when an error occurs (e.g., an invalid piece of data is entered)
- Use “try/catch/finally” or “try/catch” block to handle exceptions
- Other Specifications
You must follow the next five specifications when completing this assignment:
- Create the method displayInfo to provide appropriate information as shown below. The content of displayInfo should be the first thing that displays onscreen
- 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…
- DO NOT add any file path for ‘library.txt’ (put it directly in your project folder when you test your code)
- DO NOT add your own package name(s) to the beginning of your .java file
- DO NOT use any function to clean the screen at any stage of your program
159.234 OBJECT-ORIENTED PROGRAMMING S1, 2022 |
- Submission Requirements:
1) Zip all your source code (.java files) and submit as a single zip file to Stream
- Test data and sample outputs:
Task A: Input test data from library.txt file (supplied) into your system
Task B: List all items in the library
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
159.234 OBJECT-ORIENTED PROGRAMMING |