Lab 7-2025.03.
21
1. Indicate true or false for the following statements:
A protected datum or method can be accessed by any class in the same
package.
A protected datum or method can be accessed by any class in different
packages.
A protected datum or method can be accessed by its subclasses in any
package.
A final class can have instances.
A final class can be extended.
A final method can be overridden.
You can always successfully cast an instance of a subclass to a
superclass.
You can always successfully cast an instance of a superclass to a
subclass.
2. Design a class named Person and its two subclasses named Student
and Employee. Make Faculty and Staff subclasses of Employee. A
person has a name, address, phone number, and email address. A student
has a class status (freshman, sophomore, junior, or senior). Define the
status as a constant. An employee has an office, salary, and date hired.
Define a class named MyDate that contains the fields year, month, and
day. A faculty member has office hours and a rank. A staff member has a
title. Override the toString method in each class to display the class name
and the person’s name.
Draw the UML diagram for the classes. Implement the classes. Write a
test program that creates a Person, Student, Employee, Faculty, and
Staff, and invokes their toString() methods.
3. Design and implement a set of classes that define various types of
reading material: books, novels, magazines, technical journals, textbooks,
and so on. Include data values that describe various attributes of the
material, such as the number of pages and the names of the primary
characters. Include methods that are named appropriately for each class
and that print an appropriate message. Create a main driver class to
instantiate and exercise several of the classes.
4. Design and implement a set of classes that define the employees of a
hospital: doctor, nurse, administrator, surgeon, receptionist, janitor, and so
on. Include methods in each class that are named according to the services
provided by that person and that print an appropriate message. Create a
main driver class to instantiate and exercise several of the classes.
Submission Requirements: For each question, use a folder to include all
source files. For example, this lab contains three questions, so you need to
create three folders, each of which needs to save the source files for each
question. Then, you need to submit the compressed file containing these
folders to the Moodle platform.