eolymp
bolt
Try our new interface for solving problems
Problems

Java Person Teacher 7

Java Person Teacher 7

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 getTeacherWithMaxSalary() // Return Teacher with maximum Salary
  public Teacher getTeacherWithMaxSalary(String Subject) // Return Teacher with maximum Salary who runs the subject Subject
  public Teacher getTeacherWithMinSalary() // Return Teacher with minimum Salary
  public Teacher getTeacherWithMinSalary(String Subject) // Return Teacher with minimum Salary who runs the subject Subject
}

List of people will be created:

ListOfPeople list = new ListOfPeople();

Input data will be added to the list. Then next information will be printed:

  • Teacher with maximum Salary
  • Teacher with maximum Salary who runs Physics
  • Teacher with minimum Salary
  • Teacher with minimum Salary who runs Maths
System.out.println(list.getTeacherWithMaxSalary());
System.out.println(list.getTeacherWithMaxSalary("Physics"));
System.out.println(list.getTeacherWithMinSalary());
System.out.println(list.getTeacherWithMinSalary("Math"));

Input

Each line contains one of two types of people in the next format:

  • PersonSurname Name Age
  • TeacherSurname Name Age Subject Salary

Output

Print the next information (each data about the Teacher must be printed in a separate line):

  • Teacher with maximum Salary
  • Teacher with maximum Salary who runs Physics
  • Teacher with minimum Salary
  • Teacher with minimum Salary who runs Maths
Time limit 1 second
Memory limit 128 MiB
Input example #1
Person Ivanov Sergey 28
Teacher Petrov Ivan 34 Physics 410
Teacher Babayev Petr 28 Physics 443
Person Lenov Yuriy 21
Teacher Ermolov Kirill 44 Math 420
Teacher Fedoseev Nikita 38 Math 630
Teacher Egorova Dasha 32 Geography 450
Output example #1
Fedoseev Nikita 38 Math 630
Babayev Petr 28 Physics 443
Petrov Ivan 34 Physics 410
Ermolov Kirill 44 Math 420
Author Mykhailo Medvediev