Java Person Teacher 5
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
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 array list public int size() // Return size of array list public String toString() // Print people in array list. Each person print in a separate line public Teacher getOldestTeacher() // Return the Oldest Teacher public Teacher getOldestTeacher(String Subject) // Return the Oldest Teacher who runs the subject Subject public Teacher getYoungestTeacher() // Return the Youngest Teacher public Teacher getYoungestTeacher(String Subject) // Return the Youngest Teacher who runs the subject Subject }
List of people will be created:
ListOfPeople list = new ListOfPeople();
Input data will be added to the list. The list of Teachers will be printed in the next order:
the Oldest Teacher
the Oldest Teacher who runs Physics
the Youngest Teacher
the Youngest Teacher who runs Math
System.out.println(list.getOldestTeacher()); System.out.println(list.getOldestTeacher("Physics")); System.out.println(list.getYoungestTeacher()); System.out.println(list.getYoungestTeacher("Math"));
Input
Each line contains one of two types of people in the next format:
Person Surname Name Age
Teacher Surname Name Age Subject Salary
Output
Print each Teacher data in a separate line:
the Oldest Teacher
the Oldest Teacher who runs Physics
the Youngest Teacher
the Youngest Teacher who runs Math
Examples
Input #1
Answer #1
Submissions 572
Acceptance rate 61%