Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff

Question:

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. Use the MyDate class defined in Programming Exercise 10.14 to create an object for date hired. 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 and implement them. Write a test program that creates a Person, Student, Employee, Faculty, and Staff, and invokes their toString() methods.

Design a class named MyDate. The class contains:

■ The data fields year, month, and day that represent a date. month is 0-based, i.e., 0 is for January.

■ A no-arg constructor that creates a MyDate object for the current date.

■ A constructor that constructs a MyDate object with a specified elapsed time since midnight, January 1, 1970, in milliseconds.

■ A constructor that constructs a MyDate object with the specified year, month, and day.

■ Three getter methods for the data fields year, month, and day, respectively.

■ A method named setDate(long elapsedTime) that sets a new date for the object using the elapsed time.

Draw the UML diagram for the class and then implement the class. Write a test program that creates two MyDate objects (using new MyDate() and new MyDate(34355555133101L)) and displays their year, month, and day. (Hint: The first two constructors will extract the year, month, and day from the elapsed time. For example, if the elapsed time is 561555550000 milliseconds, the year is 1987, the month is 9, and the day is 18. You may use the GregorianCalendar class discussed in Exercise to simplify coding.)

Java API has the GregorianCalendar class in the java.util package, which you can use to obtain the year, month, and day of a date. The no-arg constructor constructs an instance for the current date, and the methods get(GregorianCalendar.YEAR), get(GregorianCalendar.MONTH), and get(GregorianCalendar.DAY_OF_MONTH) return the year, month, and day. Write a program to perform two tasks:

■ Display the current year, month, and day.

■ The GregorianCalendar class has the setTimeInMillis(long), which can be used to set a specified elapsed time since January 1, 1970. Set the value to 1234567898765L and display the year, month, and day.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: