159.234 人工智能

发布时间 2023-05-10 09:08:25作者: guhgf18


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.
1. 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.
2. 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
3. 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)

2.编程任务完成:
A. 读取文本文件library.txt(提供); 对于此文件中的每一行,创建一个 Movie/Book/Journal 对象并添加
它到你的“图书馆”对象
B.列出图书馆的所有物品,但只显示其ID、类型和标题
C. 提示问题以允许用户执行以下操作(请参阅本文末尾附带的示例输出
预期提示和显示详细信息的文档):
A。 首先按平均评分对所有项目进行排序,然后按 ID 对所有项目进行排序
b. 按标题中的 ID 或短语搜索项目,并列出找到的项目
C。 从搜索结果中选择一个项目并显示其详细信息
d. 借用所选项目(如果可用)并显示新的到期日期,或者
e. 归还所选项目(如果是借出的),或者
F。 为所选项目评分并显示新的平均评分
3. Functions工作流程(相关任务分别标记为A、B、C-a、C-b、C-d、C-d、C-e、C-f):
运行你的程序
创建库项目并将其添加到您的系统 (A) 并输出所有项目 (B)
按“id”或“标题中的短语”搜索 (C-b)
辞职
输入“id”
显示所选项目的详细信息 (C-c)
借用或评价项目 (C-d, C-f) 归还或评价项目 (C-e, C-f)
如果物品可用 如果物品借出
借出或评价后显示物品详情


159.234 OBJECT-ORIENTED PROGRAMMING S1, 2023
4. 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
5. 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
6. Submission Requirements:
1) Zip all your source code (.java files) and submit as a single zip file to Stream
7. 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
4
159.234 OBJECT-ORIENTED PROGRAMMING S1, 2023
Task C: Prompt questions to allow the user to select all the functions:
The initial value of ‘Average rating’; number of reviewers’
should be set to 0 for all items at beginning
The initial value of ‘Status’ should be set to
‘available’ for all items (none out on loan yet)
As the initial value of ‘Average rating’ is 0 for all items, list is sorted by ‘ID’
5
159.234 OBJECT-ORIENTED PROGRAMMING S1, 2023
Only one rating is available so the user
entered rating value (7 in this example) equal
to the ‘Average rating’
‘Number of reviewers’ changed from 0
to 1 after item received its first rating
Multiple ratings for an item are allowed from one user, so after
their second rating, ‘Average rating’ is: (8+7)/2=7.5
‘Number of reviewers’ changed from 1 to 2 after item’s second rating
6
159.234 OBJECT-ORIENTED PROGRAMMING S1, 2023
The item’s status changed to ‘on loan’
after being borrowed
Due date is current date + max number of
days for borrowing
To calculate date in Java, you may use java
library java.util.Calendar,
java.text.SimpleDateFormat, etc.
‘Status’ becomes ‘available’
after an item is returned
There are two items
whose titles include
‘lord’ (searching
should not be casesensitive); see ‘*1’
and ‘*2’
7
159.234 OBJECT-ORIENTED PROGRAMMING S1, 2023
This round, sort first by ‘average
rating’(descending order) and then
by ‘ID’ (ascending order)

 WX:codehelp