Ivelin_1936

class Main

Feb 11th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         Person[] persons = {
  7.                 new Employee("Ivan", 33, true, 70),
  8.                 new Employee("Ana", 28, false, 75),
  9.                 new Person("Peter", 40, true),
  10.                 new Person("Mariika", 36, false),
  11.                 new Student("Gosho", 20, true, 4.50),
  12.                 new Student("Penka", 19, false, 5.99)};
  13.  
  14.         for (Person person : persons) {
  15.             if (person.getClass().getTypeName().endsWith("Person")) {
  16.                 person.showPersonInfo();
  17.             } else if (person.getClass().getTypeName().endsWith("Student")) {
  18.                 person.showStudentInfo();
  19.             } else {
  20.                 person.showEmployeeInfo();
  21.             }
  22.         }
  23.  
  24.         for (Person person : persons) {
  25.             if (person.getClass().getTypeName().endsWith("Employee")) {
  26.                 System.out.println("Salary for overtime: " + person.calculateOvertime(2) + "lv.");
  27.             }
  28.         }
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment