Ivelin_1936

Main

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