Java Person Teacher 6#9663

Java Person Teacher 6

1 second
128 megabytes
Easy

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 int getTeachersBudget() // Return the total budget (sum of Salaries) for Teachers
  public int getTeachersBudget(String Subject) // Return the total budget (sum of Salaries) for Teachers who teaches Subject
  public double getTeachersAverageSalary() // Return the average Salary for Teachers
  public double getTeachersAverageSalary(String Subject) // Return the average Salary for Teachers who teaches Subject
}

List of people will be created:

ListOfPeople list = new ListOfPeople();

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

System.out.println(list.getTeachersBudget());
System.out.println(list.getTeachersBudget("Math"));
System.out.println(list.getTeachersAverageSalary());
System.out.println(list.getTeachersAverageSalary("Physics"));

Input

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

  • Person Surname Name Age

  • Teacher Surname Name Age Subject Salary

Output

Print the following information (each number must be printed in a separate line):

  • total Teachers budget (sum of Salaries for Teachers)

  • total Teachers budget who teaches Math

  • average Teachers Salary

  • average Teachers Salary who teaches Physics

Examples

Example 1

Loading
Loading