Implement a superclass Adult. Make two classes, Worker and Manager, that inherit from Adult. Each adult has a name and a year of birth. Each worker has a job title of “engineer” and each manager has a job title of “supervisor”. Write the class declarations, the constructors, and the methods toString for all classes. Supply a driver class that creates an array of Worker objects and sort them by the birth years. Moreover, create an array of Manager objects but sort them by the name.
Thanks for the question.
Below is the code you will be needing Let me know if you have any doubts or if you need anything to change.
Thank You !
===========================================================================
public class Adult {
private String name;
private int yearOfBirth;
public Adult() {
name = "";
yearOfBirth = 1900;
}
public Adult(String name, int yearOfBirth) {
this.name = name;
this.yearOfBirth = yearOfBirth;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getYearOfBirth() {
return yearOfBirth;
}
public void setYearOfBirth(int yearOfBirth) {
this.yearOfBirth = yearOfBirth;
}
@Override
public String toString() {
return "Name: " + getName() + ", Birth Year: " + getYearOfBirth();
}
}
=================================================================
public class Worker extends Adult {
private static final String title = "Engineer";
public Worker() {
}
public Worker(String name, int yearOfBirth) {
super(name, yearOfBirth);
}
public static String getTitle() {
return title;
}
@Override
public String toString() {
return title + ", " + super.toString();
}
}
=================================================================
public class Manager extends Adult {
private static final String title = "Supervisor";
public Manager() {
}
public Manager(String name, int yearOfBirth) {
super(name, yearOfBirth);
}
public static String getTitle() {
return title;
}
@Override
public String toString() {
return title + ", " + super.toString();
}
}
=================================================================
package f;
import four.WordList;
import java.util.Arrays;
import java.util.Comparator;
public class SortedAdults {
public static void main(String[] args) {
Worker[] workers = new Worker[5];
workers[0] = new Worker("John Doe", 1982);
workers[1] = new Worker("Peter Romanko", 1976);
workers[2] = new Worker("Jason Gillespi", 1964);
workers[3] = new Worker("Brian Obama", 1983);
workers[4] = new Worker("Donald Trump", 1967);
Manager[] managers = new Manager[5];
managers[0] = new Manager("John Doe", 1982);
managers[1] = new Manager("Peter Romanko", 1976);
managers[2] = new Manager("Jason Gillespi", 1964);
managers[3] = new Manager("Brian Obama", 1983);
managers[4] = new Manager("Donald Trump", 1967);
Arrays.sort(workers, new Comparator<Worker>() {
@Override
public int compare(Worker o1, Worker o2) {
return o1.getYearOfBirth() - o2.getYearOfBirth();
}
});
System.out.println("Sorted Workers By Birth Year: ");
for (Worker worker : workers) {
System.out.println(worker);
}
Arrays.sort(managers, new Comparator<Manager>() {
@Override
public int compare(Manager o1, Manager o2) {
return o1.getName().compareTo(o2.getName());
}
});
System.out.println("\nSorted Managers By Name: ");
for (Manager manager : managers) {
System.out.println(manager);
}
}
}
=================================================================

Implement a superclass Adult. Make two classes, Worker and Manager, that inherit from Adult. Each adult...
Implement a superclass Person. Make two classes, Student and Instructor, that inherit from Person. A person has a name and a year of birth. A student has a major, and an instructor has a salary. Writhe the class definitions, the constructors, and the methods toString for all classes. For Person the constructors should include a no-arg constructor and one that accepts in the name of the person. For student there should be a no-arg constructor and a constructor that accepts...
Java Create four classes: 1. An Animal class that acts as a superclass for Dog and Bird 2. A Bird class that is a descendant of Animal 3. A Dog class that is a descendant of Animal 4. A “driver” class named driver that instantiates an Animal, a Dog, and a Bird object. The Animal class has: · one instance variable, a private String variable named name · a single constructor that takes one argument, a String, used to set...
Problem: Develop the ‘Shape’ application such that: · ‘Rectangle’, ‘Ellipse’, and ‘Triangle’ classes inherit from the ‘Shape’ class. · Develop the ‘Square’ and ‘Circle’ class where ‘Square’ inherits from ‘Rectangle’ and ‘Circle’ inherits from ‘Ellipse’. ‘Triangle’ has no derived class. · For each class, implement the overridden methods ‘draw’, ‘move’, and ‘erase’. Each method should only have an output statement such as “Rectangle – draw method” that will be displayed when the method is invoked. · Implement the default constructors...
Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable<Book> in the class definition. Now, all book objects are instances of the java.lang.Comparable interface. Write a test program that creates an array of ten books. 1. Use Arrays.sort( Book[]l books) from the java.util package to sort the array. The order of objects in the array is determined using compareTo...) method. 2. Write a method that returns the most expensive book in the...
Write an abstract class “Student” and three concrete classes, “UnderGrad” and “Graduate” both inherit from Student and “PostGraduate” that inherits form “Graduate”. Write the class definition for the abstract class “Student”. The class definition should include private instance variables of type String to hold the student’s first name, a string for his/her major and an int to hold the number of units taken. Getter and setter methods for each of the variables should be included in the class definition. Also...
Computer Programming II (CS141) Q.1. Why would you use an inner class instead of regular class? Q.2. What does this code print? Why is it polymorphic? DataSet data = new DataSet(); data.add(new BankAccount(1000)); data.add(new Coin(0.1, "dime")); System.out.println(data.getAverage()); Q.3. Can you convert a superclass reference into a subclass reference? A subclass reference into a superclass reference? If so, give examples. If not, explain why not. Q.4. Implement a superclass Person. Make two classes, Student and Instructor that inherit from Person. A...
ONLY NEED THE DRIVER CLASS PLEASE!!! Domain & Comparator Classes: 0.) Design a hierarchy of classes, where the Media superclass has the artistName and the mediaName as the common attributes. Create a subclass called CDMedia that has the additional arrayList of String objects containing the songs per album. Create another subclass called DVDMedia that has the additional year the movie came out, and an arrayList of co-stars for the movie. 1.) The superclass Media will implement Comparable, and will define...
Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman, sophomore, junior, or senior). Define the possible status values using an enum. Staff has an office, salaray, and date-hired. Implement the above classes in Java. Provide Constructors for classes to initialize private variables. Getters and setters should only be provided if needed. Override the toString() method...
In Java Kindly be sure to take in user input and store the 3 worker classes in an ArrayList Create a class Worker. Your Worker class should include the following attributes as String variables: Name, Worker ID, Worker Address, Worker City, Worker State Create the constructor that initializes the above worker attributes. Then make another class name HourlyWorker that inherits from the Worker class. HourlyWorker has to use the inherited parent class variables and add in hourlySalary and billableHours. Your...
a c++ program (The Person, Student, Employee, Faculty, and Staff classes) 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 classto create an object for date hired. A faculty...