Java21 Assignment Instructions
Java21 Assignment Instructions
Note: As this is not a UML course, the above diagram is an overview. Also, for those of you for which English is not you first language and/or you are not
familiar with Universities, a Faculty contains several Departments.
Page 1 of 7
This is a successor to the Java 17 assignment. If you have not done the Java 17 assignment, please do it
before this one, BUT make all classes/interfaces are public – it will make this Java 21 assignment easier.
Refactoring since Java 17 assignment: The fact that this Java 21 assignment uses an unnamed class and an
instance main() method as an entry point, has several implications for the Java 17 implementation:
• The UML University class from the Java 17 assignment no longer exists. The file University.java is
retained but is re-factored to be an unnamed class with an instance main() entry point.
o note that an unnamed class cannot reside in a named package so the “package assignment” in
University.java (from Java 17) must be removed/commented out.
• As the unnamed class is now in an unnamed package, this poses 2 issues when accessing classes in
named packages:
o to access classes in named packages, an unnamed class must import them (or namespace
qualify them). A general import java21.assignment.*; is cleanest.
o in order to import them, the classes (in the named packages) must be public and not package-
private:
▪ as many of the classes/interfaces in the Java 17 assignment were package-private this
requires refactoring – as you can now see in the UML, all of the classes/interfaces
are now public
▪ if you are modifying the Java 17 assignment then you need to create separate files for
each class/interface (as the filename must match the name of the public
class/interface).
▪ the default constructors for these classes will follow the access on the class, so they
will be public
• Given these changes, I took the opportunity to rename the package to “java21.assignment”.
The following instructions will help in coding the assignment:
• University
o this is an unnamed class with an instance main() method
o in the main() method do the following:
• invoke the seqColl() method – see the method for instructions.
• invoke the seqSet() method – see the method for instructions.
• invoke the seqMap() method – see the method for instructions.
• create a LecturerRecord for “Mike Bloggs”; who is 44; works in the software
engineering department in the engineering faculty.
• you will need instances of SoftwareEngineeringDept and EngineeringFaculty
when creating your LecturerRecord.
• invoke the method recordPatterns() passing the reference down. Sample output: As
he is only 44, nothing will be output.
• create a LecturerRecord for “Alan Austin”; who is 64; works in the accounting
department in the business faculty.
• you will need instances of AccountingDept and BusinessFaculty when creating
your LecturerRecord.
Page 2 of 7
• invoke the method recordPatterns() passing the reference down. Sample output:
• create a LecturerRecord for “Lisa Bloggs”; who is 65; works in the social care
department in the humanities faculty.
• you will need instances of SocialCareDept and HumanitiesFaculty when
creating your LecturerRecord.
• invoke the method recordPatterns() passing the reference down. Sample output:
Page 3 of 7
• remove the last element from the collection
• using an enhanced-for loop, process the collection from the beginning to the end
• using an enhanced-for loop, process the collection from the end to the beginning
Page 4 of 7
• retrieve the first element in the collection
• using an enhanced-for loop, process the collection from the beginning to the end
• using an enhanced-for loop, process the collection from the end to the beginning
Page 5 of 7
• output the collection
• using an enhanced-for loop, process the collection from the beginning to the end;
output both the keys and values.
Page 6 of 7
• using an enhanced-for loop, process the collection from the end to the beginning;
output both the keys and values.
Page 7 of 7