Question
In this task, It's required to provide complete class definitions and then create instances of various classes and use methods to perform various tests. (a)
In this task, It's required to provide complete class definitions and then create instances of various classes and use methods to perform various tests.
(a) Define an abstract class called Staff with the following fields and methods:
Fields: name, id, position representing the name, staff id and the position of a staff member in an organisation. Encapsulation should be used to protect these fields against intentional or accidental, direct modification
Constructors: a no-args/default constructor, and an overloaded constructor to initialise the fields to appropriate values when the instances of the class are created
Methods: a toString() method to print a string representation of the objects, get and set methods to provide access to each of the three fields
(b) Define a subclass of the Staff class called FullTimeStaff with the following additional field and methods:
Field: researchArea,a string variable representing the research are of the staff member. Again, encapsulation should be used to protect this field against intentional or accidental, direct modification
Constructors: a no-args/default constructor, and an overloaded constructor to initialise the fields to appropriate values when the instances of the class are created
Methods: a toString() method to print a string representation of the objects, additional get and set methods as required to provide access to the field
(c) Define a subclass of the Staff class called PartTimeStaff with the following additional field and methods:
Field: timeFraction representing the time fraction of a part-time staff member. This would be a number between 0.1 and 1.0. Again, encapsulation should be used to protect this field against intentional or accidental, direct modification
Constructors: a no-args/default constructor, and an overloaded constructor to initialise the fields to appropriate values when the instances of the class are created
Methods: a toString() method to print a string representation of the objects, additional get and set methods as required to provide access to the field
(d) Define another subclass of the Staff class called CasualStaff with the following additional field and methods:
Field: hours representing the number of hours that the casual staff member works at the organisation. Again, encapsulation should be used to protect this field against intentional or accidental, direct modification
Constructors: a no-args/default constructor, and an overloaded constructor to initialise the fields to appropriate values when the instances of the class are created
Methods: a toString() method to print a string representation of the objects, additional get and set methods as required to provide access to the field
(e) Finally, define another class called TestStaff with a main() method to perform necessary testing for the classes defined in the previous sections. In the main method, write the code to: (1) create an ArrayList object to store references to Staff objects; (2) open a text file named staff.txt (available on interact resources), which contains data relating to staff members, create FullTimeStaff, PartTimeStaff and CasualStaff objects based on the first field in each row in the file (full, part, or casual); (3) add these objects to the ArrayList; and (4) test various methods of the objects using loop(s) and methods as necessary, including the code to:
Repeatedly display a menu of five options (1, 2, 3, 4 and 5) such that
Option 1 will display details of only full-time staff
Option 2 will display details of only part-time staff
Option 3 will display details of only casual staff
Option 4 will display details of all staff
Option 5 terminate the program ?------------------------------- Staff.txt ---------------------------- casual Peter 654321 lecturer 10 full Mary 123456 convenor forensics part Raja 222222 teacher 0.5 part Shirin 111111 timetabler 0.8 casual Recep 231654 technician 16 full Anna 555666 lecturer ethics full Musa 712217 teacher security part Jasmin 555555 finance 0.4 casual Manoj 527281 teacher 12 casual Ali 322224 lecturer 8 part Bella 123332 lecturer 0.7 full Alice 454545 moderator linguistics
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started