Task Description
You have been appointed Keeper of the Hogwarts Archive, entrusted with the vital task of maintaining the records of every student and spellbook in the school. Your Java program must manage student accounts, track spellbook rentals, and preserve detailed histories, ensuring that no tome is lost or misused. You will catalogue spellbooks individually or as collections, and implement commands to list, rent, return, and save them. Accuracy and efficiency are paramount, as the very knowledge of Hogwarts depends on the integrity of your archive.
You are encouraged to ask questions on Ed under the assignments category if you are unsure of the specification - but staff members will not be able to do any coding or debugging in this assignment for you. As with any assignment, make sure that your work is your own, and do not share your code or solutions with other students.
Working on your assignment
You can work on this assignment on your own computer or the lab machines. It is important that you continually back up your assignment files onto your own machine, external drives, and in the cloud.
You are encouraged to submit your assignment on Ed while you are in the process of completing it. By submitting you will obtain some feedback on your progress on the sample test cases provided.
Implementation details
Write a program in Java that implements the Hogwarts Archive application. You can assume that our test cases will contain only valid input commands and not cause any integer overflows. All commands are case insensitive.
Hogwarts Archive stores collections of Student accounts and Spellbook objects. Student accounts are identified by their student number, and store their name, the spellbooks they are currently renting, and their rental history. Student numbers start at 100000 and increment up (such that the second Student account will have student number 100001). Multiple students may have the same name, but they must be assigned different student numbers.
A Spellbook is identified by its serial number, and store the title, inventor, type, student currently renting, and rental history. Students are able to rent and return spellbooks, with only one student able to rent a spellbook at any time. Spellbooks are considered copies of each other if they have the same title and inventor (note that copies of a spell all have different serial numbers).
Spellbook collections can be read from and archived in a CSV (comma-separate values) file, stored in order of serial number in the following form.
Example: 111111,Advanced Potion Making,Libatius Borage,Curse
A spellbook.csv template containing this example has been provided in Resources. You may wish to add further entries yourself to test your program.
Spellbooks can be added to Hogwarts Archive, either individually or as a whole collection. If any serial numbers are already present in the system, those spellbooks should not be added.
Your program will read from standard input and write to standard output. Your program output must match the exact output format shown in the examples and on Ed, including all whitespace and formatting. You are encouraged to submit your assignment while you are working on it, so you can obtain some feedback.
We have provided a scaffold for the HogwartsArchive class, however outside of this you must design and implement your own classes to achieve the required functionality.
In order to obtain full marks, your program will be checked against automatic test cases, manually inspected by your tutors and you must submit a set of test cases that ensure you have implemented functionality correctly.
Commands
Your program should implement the following commands, look at the examples to see how they work. Commands with [LONG] contain optional items that modify the functionality. ... represents a variable number of items.
Additional notes:
• HISTORY commands output the result in chronological order (i.e. order of rental).
Rental history is only logged after the spellbook is returned, i.e. spellbooks are only included in the student’s history once they have been returned and spellbook history only includes past students who have already returned the spellbook.
• INVENTOR, TYPE, and COMMON commands output the result in alphabetical order.
• The program should ignore any invalid commands (e.g. TESTINPUT 10000), but should respond to valid edge cases (e.g. queries before there are any registered books or students). Please see the examples below for the expected output in these cases.
Examples
The examples below show the expected behaviour of the commands.
Example 1
user: LIST ALL
No spellbooks in system.
user: LIST TYPES
No spellbooks in system.
user: LIST INVENTORS
No spellbooks in system.
user: STUDENT 100000 No students in system.
user: RENT 100000 111111 No students in system.
user: RELINQUISH 100000 111111 No students in system.
user: RELINQUISH ALL 100000 No students in system.
user: LIST ALL LONG
No spellbooks in system.
user: EXIT
Ending Archive process.
Example 2
user: ADD STUDENT Harry Potter Success.
user: ADD SPELLBOOK spellbooks.csv 111111
Successfully added: The Standard Book of Spells Grade 1 (Miranda Goshawk)
user: ADD COLLECTION spellbooks.csv
16 spellbooks successfully added.
user: RENT 100000 111111 Success.
user: RELINQUISH 100000 111111 Success.
user: LIST ALL
The Standard Book of Spells Grade 1 (Miranda Goshawk)
The Standard Book of Spells Grade 2 (Miranda Goshawk)
The Standard Book of Spells Grade 3 (Miranda Goshawk)
The Standard Book of Spells Grade 4 (Miranda Goshawk)
The Standard Book of Spells Grade 5 (Miranda Goshawk)
The Standard Book of Spells Grade 6 (Miranda Goshawk)
The Standard Book of Spells Grade 7 (Miranda Goshawk) Dark Charms and their Defense (Quentin Trimble)
Curses and Counter-Curses (Vindictus Viridian)
The Healer’s Handbook (Hippocrates Smethwyck)
The Dragonkeeper’s Guide (Harvey Ridgebit)
The Marauder’s Manual of Mischief (Gellert Grindelwald)
The Jokester’s Treasury of Jinxes (Zacharias Mumps)
A Beginner’s Guide to Transfiguration (Emeric Switch) Intermediate Transfiguration (Emeric Switch)
Advanced Transfiguration (Emeric Switch)
Practical Guide to Unbinding Viridian’s Curses (Eldritch Diggory)
user: SPELLBOOK HISTORY 111112 No rental history.
user: EXIT
Ending Archive process.
Example 3
user: ADD STUDENT Hermione Granger Success.
user: STUDENT 100000
100000: Hermione Granger
user: STUDENT 20000
No such student in system.
user: STUDENT SPELLBOOKS 100000 Student not currently renting.
user: STUDENT HISTORY 100000 No rental history for student.
user: RENT 100000 111111
user: No spellbooks in system.
user: ADD SPELLBOOK spellbooks.csv 111111
Successfully added: The Standard Book of Spells Grade 1 (Miranda Goshawk) .
user: RENT 100000 111111 Success.
user: STUDENT SPELLBOOKS 100000
The Standard Book of Spells Grade 1 (Miranda Goshawk)
user: RELINQUISH 100000 111111 Success.
user: STUDENT SPELLBOOKS 100000 Student not currently renting.
user: STUDENT HISTORY 100000
The Standard Book of Spells Grade 1 (Miranda Goshawk)
user: EXIT
Ending Hogwarts process.
Example 4
user: ADD STUDENT Ron Weasley Success.
user: ADD STUDENT Draco Malfoy Success.
user: ADD COLLECTION spellbooks.csv
17 spellbooks successfully added.
user: RENT 100000 111111 Success.
user: RENT 100000 111112 Success.
user: RENT 100000 111113 Success.
user: RENT 100001 111111
Spellbook is currently unavailable.
user: RELINQUISH ALL 100000 Success.
user: RENT 100001 111112 Success.
user: RENT 100001 111113 Success.
user: RELINQUISH ALL 100001 Success.
user: COMMON 100000 100001
The Standard Book of Spells Grade 2 (Miranda Goshawk)
The Standard Book of Spells Grade 3 (Miranda Goshawk)
user: EXIT
Ending Hogwarts process.
Example 5
user: ADD STUDENT Neville Longbottom Success.
user: ADD STUDENT Lavender Brown Success.
user: ADD STUDENT Pansy Parkinson Success.
user: ADD SPELLBOOK spellbooks.csv 111111
Successfully added: The Standard Book of Spells Grade 1 (Miranda Goshawk).
user: SPELLBOOK 111111
The Standard Book of Spells Grade 1 (Miranda Goshawk)
user: SPELLBOOK 111111 LONG
111111: The Standard Book of Spells Grade 1 (Miranda Goshawk, Charm) Currently available.
user: RENT 100000 111111 Success.
user: SPELLBOOK 111111 LONG
111111: The Standard Book of Spells Grade 1 (Miranda Goshawk, Charm)
Rented by: 100000.
user: RELINQUISH 100000 111111 Success.
user: RENT 100001 111111 Success.
user: RELINQUISH ALL 100001 Success.
user: RENT 100002 111111 Success.
user: SPELLBOOK HISTORY 111111 100000
100001
user: EXIT
Ending Archive process.
Example 6
user: ADD COLLECTION spellbooks.csv
17 spellbooks successfully added.
user: LIST TYPES Charm
Counter-spell Curse
Healing Hex
Jinx
Transfiguration
user: LIST INVENTORS Eldritch Diggory
Emeric Switch
Gellert Grindelwald
Harvey Ridgebit
Hippocrates Smethwyck Miranda Goshawk
Quentin Trimble Vindictus Viridian Zacharias Mumps
user: TYPE Charm
The Standard Book of Spells Grade 1 (Miranda Goshawk)
The Standard Book of Spells Grade 2 (Miranda Goshawk)
The Standard Book of Spells Grade 3 (Miranda Goshawk)
The Standard Book of Spells Grade 4 (Miranda Goshawk)
The Standard Book of Spells Grade 5 (Miranda Goshawk)
The Standard Book of Spells Grade 6 (Miranda Goshawk)
The Standard Book of Spells Grade 7 (Miranda Goshawk)
user: INVENTOR Quentin Trimble
Dark Charms and their Defense (Quentin Trimble)
user: EXIT
Ending Archive process.
Example 7
user: COMMANDS
EXIT ends the archive process
COMMANDS outputs this help string
LIST ALL [LONG] outputs either the short or long string for all spellbooks
LIST AVAILABLE [LONG] outputs either the short of long string for all available spellbooks NUMBER COPIES outputs the number of copies of each spellbook
LIST TYPES outputs the name of every type in the system
LIST INVENTORS outputs the name of every inventor in the system
TYPE outputs the short string of every spellbook with the specified type
INVENTOR outputs the short string of every spellbook by the specified inventor
SPELLBOOK [LONG] outputs either the short or long string for the specified
spellbook
SPELLBOOK HISTORY outputs the rental history of the specified spellbook
STUDENT outputs the information of the specified student
STUDENT SPELLBOOKS outputs the spellbooks currently rented by the specified student
STUDENT HISTORY outputs the rental history of the specified student
RENT loans out the specified spellbook to the given student RELINQUISH returns the specified spellbook from the
student
RELINQUISH ALL returns all spellbooks rented by the specified student
ADD STUDENT adds a student to the system
ADD SPELLBOOK adds a spellbook to the system
ADD COLLECTION adds a collection of spellbooks to the system SAVE COLLECTION saves the system to a csv file
COMMON ... outputs the common spellbooks in students' history
user: EXIT
Ending Archive process.
Example 8
user: ADD STUDENT Harry Potter Success.
user: ADD STUDENT Hermione Granger Success.
user: ADD COLLECTION spellbooks.csv
17 spellbooks successfully added.
user: COMMON 100000 100000 Duplicate students provided.
user: COMMON 100000 100001 No common spellbooks.
user: RENT 100000 111112 Success.
user: RENT 100000 111111 Success.
user: RELINQUISH ALL 100000 Success.
user: RENT 100001 111112 Success.
user: RENT 100001 111111 Success.
user: RELINQUISH ALL 100001 Success.
user: COMMON 100000 100001
The Standard Book of Spells Grade 1 (Miranda Goshawk)
The Standard Book of Spells Grade 2 (Miranda Goshawk)
user: STUDENT HISTORY 100001
The Standard Book of Spells Grade 2 (Miranda Goshawk)
The Standard Book of Spells Grade 1 (Miranda Goshawk)
user: EXIT
Ending Archive process.
Example 9
user: ADD SPELLBOOK spellbooks.csv 111111
Successfully added: The Standard Book of Spells Grade 1 (Miranda Goshawk).
user: ADD SPELLBOOK spellbooks_2.csv 111112
Successfully added: The Standard Book of Spells Grade 1 (Miranda Goshawk).
user: ADD SPELLBOOK spellbooks.csv 111113
Successfully added: The Standard Book of Spells Grade 2 (Miranda Goshawk).
user: NUMBER COPIES
The Standard Book of Spells Grade 1 (Miranda Goshawk): 2
The Standard Book of Spells Grade 3 (Miranda Goshawk): 1
user: ADD SPELLBOOK spellbooks.csv 111114
Successfully added: The Standard Book of Spells Grade 3 (Miranda Goshawk).
user: ADD SPELLBOOK spellbooks_2.csv 111115
Successfully added: The Standard Book of Spells Grade 3 (Miranda Goshawk).
user: NUMBER COPIES
The Standard Book of Spells Grade 1 (Miranda Goshawk): 2
The Standard Book of Spells Grade 2 (Miranda Goshawk): 1
The Standard Book of Spells Grade 3 (Miranda Goshawk): 2
user: EXIT
Ending Archive process.
Example 10
user: ADD STUDENT Harry Potter Success.
user: ADD STUDENT Hermione Granger Success.
user: COMMON 100000 100001 No spellbooks in system.
user: ADD SPELLBOOK collections/spellbooks.csv 111111
Successfully added: The Standard Book of Spells Grade 1 (Miranda Goshawk).
user: RELINQUISH 100000 111111 Unable to return spellbook.
user: COMMON 100000 invalid No such student in system.
user: RENT 100000 111111 Success.
user: LIST AVAILABLE
No spellbooks available.
user: EXIT
Ending Archive process.
Marking Criteria (20%)
Your mark consists of four components: your assignment code (submitted via Ed), your test cases (submitted via Ed together with the code), your demo (conducted during week 12), and your report / UML (submitted via Canvas). Marking will include both automatic marking via test cases and manual inspection by tutors.
Functionality (10%)
You must submit your code and tests using the assignment page on Ed.To submit, simply place your files and folders into the workspace, click run to check your program works and then click submit. You are encouraged to submit multiple times, but only your last submission will be considered.
Marks are assigned based on automatic tests for the correctness of your program. You will only be given valid inputs as part of the test suite. Your program will be checked for errors that a user can possibly make and must match the exact output in the examples and test cases on Ed. In addition to the visible test cases, we will mark your program against a substantial collection of hidden test cases that cover every aspect of the specification.
Test cases (3%)
We have provided you with some test cases but these do not test all the functionality described in the assignment. It is important that you thoroughly test your code by writing your own test cases. You should place all of your test cases in a tests/ directory, and these will be submitted alongside your codebase on Ed.
Tests will be manually assessed by your tutors. You need to write at least 2 test cases per command (except for EXIT and COMMANDS, which only require 1 test case each). Each test case should meaningfully check a different aspect of that command’s functionality. Ensure that each test case has a .in input file along with a corresponding .out output file. We require that the names of your test cases are descriptive so that you know what each is testing, prefixed by the name of the command e.g. student_account_numbering.in & student_account_numbering.out and we can accurately and quickly assess your test cases.
Note: If you do not format your test case files as explained (where each test case has .in and .out files for input and output), you shall receive 0 for this component.
Demo / Viva (4%)
The demonstration is conducted during tutorials in week 12, where you will be asked to show the functionality to your tutor and they will ask you questions about your codebase and how you implemented the functionality.
Design, Report, and UML (3%)
You will need to submit a report that elaborates on your design through Canvas. This will include an explanation of any object-oriented design decisions made (such as reasons for class structure, interactions between classes, inheritance etc.). This should be no longer than 500 words.
You will need to submit a UML diagram in PDF form. through Canvas. This will provide a brief graphical overview of your code design and use of Object Oriented Principles such as encapsulation, inheritance, etc.. Markers will use this to determine whether you have appropriately used those principles to aid you in your design, as well as figure out whether more should have been done. A general guideline is that markers will be looking for is clean class structure, separation of concerns, how extensible the code is, and penalising repeated code.
IDE-generated UMLs, ASCII diagrams, and hand-drawings are not acceptable and will receive 0 marks. We suggest using an online diagramming tool such as draw.io or LucidChart.
Your code submission will be inspected manually to check whether it is clear, well documented and concise. Try to utilise OOP constructs within your application and limit repetitive code. The code should follow the conventions set out by the Google Java Style Guide.
Report, UML and OO design: 2%
Code style. and readability: 1%
Learning outcomes
This assignment covers the following Learning outcomes of this UoS:
LO1. Demonstrate an understanding of the concept of Object-Orientation: understand and explain key concepts of object-oriented programming, including classes as encapsulating data, object instances, memory model of references, methods and calling them across objects.
LO2. Demonstrate an understanding of Object-Oriented programming language: reading, tracing and writing competence with the following elements of Java programming language: classes, methods, object creation; instance and local variables, parameters and scope; basic types; simple I/O; control flow primitives and understand, modify and add functionality to Java programs
LO3. Read and interpret object-oriented design documents, including basic UML diagrams.
LO4. Create appropriate class/data structure including the data types and methods for simple problems.
LO5. Derive a computer program from a design document that uses concepts of OO and memory model, trace and write small examples of code including the following elements: inheritance, polymorphism, abstract classes and interfaces, variables and their type and the relationship between static and dynamic type, exception
LO6. Demonstrate experience in testing Object-Oriented programs, write tests for standalone objects, be able to generate and handle exceptions, create invariants for classes, methods and objects, pre- and post-conditions for methods, and assertions
LO7. Demonstrate experience in testing and debugging Object-Oriented programs, write tests for stand-alone object code, to be run automatically.
LO8. Demonstrate experience with common interfaces and collections in Java.