0% found this document useful (0 votes)
2 views

Java17 Assignment Instructions

The document provides detailed instructions for a Java 17 assignment involving the creation of classes for Departments and Faculties, along with a LecturerRecord class. It outlines the structure, methods, and error handling required for each class, including specific output messages and exception handling. Additionally, it includes examples for testing the implementation in a main method, demonstrating the functionality of the created classes.

Uploaded by

gs23133
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java17 Assignment Instructions

The document provides detailed instructions for a Java 17 assignment involving the creation of classes for Departments and Faculties, along with a LecturerRecord class. It outlines the structure, methods, and error handling required for each class, including specific output messages and exception handling. Additionally, it includes examples for testing the implementation in a main method, demonstrating the functionality of the created classes.

Uploaded by

gs23133
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Java 17 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 6
The following instructions will help in coding the assignment:

 the package name is assignment


 the Department type and all its subtypes are in the Department.java file
o Department is public; all its subtypes are package-private
o Department is abstract and sealed; its subtypes are final
o ComputerEngineeringDept:
 compEng() method: output “Custom computer engineering” (a simple tracer message)
 toString() method: returns “Computer Engineering”
o SoftwareEngineeringDept:
 swEng() method: output “Custom software engineering” (a simple tracer message)
 toString() method: returns “Software Engineering”
o SocialCareDept:
 socialCare() method: output “Custom social care” (a simple tracer message)
 toString() method: returns “Social Care”
o AccountingDept:
 accounting() method: output “Custom accounting” (a simple tracer message)
 toString() method: returns “Accounting”
 the Faculty type and all its subtypes are in the Faculty.java file
o Faculty implements the interface Educational
 Educational is a marker interface (no methods) and is sealed and package-private
o Faculty is public; all its subtypes are package-private
o Faculty is abstract and sealed; its subtypes are final
o EngineeringFaculty:
 engineering() method: output “We teach computer science, civil engineering etc…”
 toString() method: returns “Engineering”
o HumanitiesFaculty:
 humanities() method: output “We teach social care, European studies etc…”
 toString() method: returns “Humanties”
o BusinessFaculty:
 business() method: output “We teach accountancy, law, economics etc…”
 toString() method: returns “Business”

Page 2 of 6
 LecturerRecord
o final by default (insert final anyway)
o the record contains 4 instance variables in this order:
 a String name
 an Integer age
 a Faculty reference called faculty
 a Department reference called dept
o insert a custom compact constructor:
 if the name passed in is blank (hint: use the isBlank() method) or the age passed in
negative we will throw an IllegalArgumentException with a custom message. The
custom message is built as follows:
 using a text block we can use the String method formatted to insert both the
name and age parameters into the custom error message; this can be done as
follows:

o hasPhd() method:
 we need to cater for someone using “Dr.” at the start of their name or “PhD” at the
end of their name.
 figure out the prefix (first 3 characters) and suffix (last 3 characters) in the name.
Hint: one option is to use the substring() method from String
 using nested switch expressions, return true if the lecturers name begins with “Dr.”
or ends with “PhD”; return false otherwise.
o whichFaculty() method:
 switch on the faculty:
 using a switch expression pattern matching:
o if it’s the EngineeringFaculty then in a code block do the following:
 call toString() on the reference, prepended with
“Faculty of: “ i.e. assuming eng is the reference, code
System.out.println(“Faculty of: “+eng);
 call the custom method engineering()
o if it’s the HumanitiesFaculty then in a code block do the following:
 call toString() on the reference prepended with “Faculty of: “
 call the custom method humanities()
o if it’s the BusinessFaculty then in a code block do the following:
 call toString() on the reference prepended with “Faculty of: “
 call the custom method business()
o otherwise, throw an IllegalArgumentException, outputting the faculty
that is causing the error in the error message.

Page 3 of 6
o whichDept() method:
 switch on the department:
 using a switch expression pattern matching:
o if it’s the ComputerEngineeringDept then in a code block do the
following:
 call toString() on the reference prepended with “Dept of: “
 call the custom method compEng()
o if it’s the SoftwareEngineeringDept then in a code block do the
following:
 call toString() on the reference prepended with “Dept of: “
 call the custom method swEng()
o if it’s the SocialCareDept then in a code block do the following:
 call toString() on the reference prepended with “Dept of: “
 call the custom method socialCare()
o if it’s the AccountingDept then in a code block do the following:
 call toString() on the reference prepended with “Dept of: “
 call the custom method accounting()
o otherwise, throw an IllegalArgumentException, outputting the
department that is causing the error in the error message.
 University
o in the main() method do the following:
 Force an exception by creating a LecturerRecord that has either a blank name and/or a
negative age. Test both scenarios. Sample output:

Page 4 of 6
 Create a LecturerRecord with the following details: the lecturers name is “Jane
Bloggs”; she is 24; she works in the Engineering faculty and is in the Software
Engineering Department. Output the details by calling toString(). Sample output:

 Now, rather than using toString(), we will output Jane’s details individually by calling
each accessor method in turn. Sample output:

 Invoke the whichFaculty() on Jane’s reference. Sample output:

 Invoke the whichDept() on Jane’s reference. Sample output:

 Does Jane have a PhD? Sample Output:

 Create a record for “Dr. Anne Bloggs”; she is 35 and works in the Accounting
department in the faculty of Business. Output her details (toString()) and whether or
not she has a PhD. In this case we will decorate the output i.e. rather than simply
returning true/false, we will use a ternary operator to output “Ann has a PhD” or
“Anne has not a PhD”, depending on true/false respectively. Sample output:

Page 5 of 6
 “Joe Bloggs PhD” is 54 and is a member of staff in the Social Care department in the
faculty of Humanities. Create a record representing him. Output his details
(toString()) and whether or not he has a PhD (again, decorate the output). Sample
output:

Page 6 of 6

You might also like