Implement a class Person.
Implement a class Teacher that extends Person.
class Person
{
protected String Surname, Name;
protected int Age;
Person(String Surname, String Name, int Age) // Constructor
public String toString() // Print Surname Name Age
}
class Teacher extends Person
{
protected String Subject;
protected int Salary;
Teacher(String Surname, String Name, int Age, String Subject, int Salary) // Constructor
Teacher(Teacher a) // Copy constructor
public String toString() // Print Surname Name Age Subject Salary
}
class ListOfPeople
{
ArrayList<Person> a = new ArrayList<Person>();
public void add(Person p) // Add person p to the array list
public int size() // Return the size of the array list
public String toString() // Print people in the array list. Each person on a separate line
public Teacher getOldestTeacher() // Return the oldest Teacher
public Teacher getOldestTeacher(String Subject) // Return the oldest Teacher who teaches the subject Subject
public Teacher getYoungestTeacher() // Return the youngest Teacher
public Teacher getYoungestTeacher(String Subject) // Return the youngest Teacher who teaches the subject Subject
}The list of people is created as follows:
ListOfPeople list = new ListOfPeople();Input data will be added to the list. The list of teachers will be printed in the following order:
the oldest Teacher
the oldest Teacher who teaches Physics
the youngest Teacher
the youngest Teacher who teaches Math
System.out.println(list.getOldestTeacher());
System.out.println(list.getOldestTeacher("Physics"));
System.out.println(list.getYoungestTeacher());
System.out.println(list.getYoungestTeacher("Math"));Each line contains a person in one of the following formats:
Person
Teacher
Print each Teacher's data on a separate line in the following order:
the oldest Teacher
the oldest Teacher who teaches Physics
the youngest Teacher
the youngest Teacher who teaches Math
Beispiel 1