Задачи
Java Человек Учитель 3
import java.util.ArrayList;
class Person { protected String Surname, Name; protected int Age;
Person(String Surname, String Name, int Age) {
this.Surname = Surname;
this.Name = Name;
this.Age = Age;
}
public String toString() {
return Surname + " " + Name + " " + Age;
}
}
class Teacher extends Person { protected String Subject; protected int Salary;
Teacher(String Surname, String Name, int Age, String Subject, int Salary) {
super(Surname, Name, Age);
this.Subject = Subject;
this.Salary = Salary;
}
public String toString() {
return super.toString() + " " + Subject + " " + Salary;
}
}
class ListOfPeople { ArrayList<Person> a = new ArrayList<Person>();
public void add(Person p) {
a.add(p);
}
public int size() {
return a.size();
}
public String toString() {
StringBuilder result = new StringBuilder();
for (Person p : a) {
result.append(p.toString()).append("\n");
}
return result.toString();
}
public ListOfPeople getTeachers() {
ListOfPeople teachersList = new ListOfPeople();
for (Person p : a) {
if (p instanceof Teacher) {
teachersList.add(p);
}
}
return teachersList;
}
public int GetNumberOfTeachers() {
int count = 0;
for (Person p : a) {
if (p instanceof Teacher) {
count++;
}
}
return count;
}
public ListOfPeople getNotTeachers() {
ListOfPeople notTeachersList = new ListOfPeople();
for (Person p : a) {
if (!(p instanceof Teacher)) {
notTeachersList.add(p);
}
}
return notTeachersList;
}
public int GetNumberOfNotTeachers() {
int count = 0;
for (Person p : a) {
if (!(p instanceof Teacher)) {
count++;
}
}
return count;
}
}