Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package HomeWrok;
- import java.util.ArrayList;
- import java.util.List;
- public class HomeWork {
- static class Person{
- private String name;
- private String type;
- public Person(String name, String type) {
- this.name = name;
- this.type = type;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getType() {
- return type;
- }
- public void setType(String type) {
- this.type = type;
- }
- @Override
- public String toString() {
- return String.format("%s is %s", this.name, this.type);
- }
- }
- public static void main(String[] args) {
- List<Person> people = new ArrayList<>();
- Person normalPerson1 = new Person("Gosho", "normalPerson");
- Person normalPerson2 = new Person("Pesho", "normalPerson");
- Person professor1 = new Person("Einstein", "Professor");
- Person professor2 = new Person("Tesla", "Professor");
- Person student1 = new Person("Mariika", "Student");
- Person student2 = new Person("Ivancho", "Student");
- Person richStudent1 = new Person("Richy", "RichStudent");
- Person richStudent2 = new Person("GoldyBoy", "RichStudent");
- people.add(normalPerson1);
- people.add(normalPerson2);
- people.add(professor1);
- people.add(professor2);
- people.add(student1);
- people.add(student2);
- people.add(richStudent1);
- people.add(richStudent2);
- showStats(people);
- }
- private static void showStats(List<Person> people) {
- int professorCounter = 0;
- int studentCounter = 0;
- int richStudentCounter = 0;
- for (Person person : people) {
- if (person.getType().equals("Student")){
- studentCounter++;
- study(person);
- }else if (person.getType().equals("Professor")){
- professorCounter++;
- }else if (person.getType().equals("RichStudent")){
- richStudentCounter++;
- study(person);
- }
- }
- System.out.printf("Students are: %d%n", studentCounter);
- System.out.printf("Rich Students are: %d%n", richStudentCounter);
- System.out.printf("Professors are: %d%n", professorCounter);
- System.out.printf("List contains: %d people %n", people.size());
- }
- private static void study(Person person) {
- System.out.println(person.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement