maygapixel

Untitled

Feb 27th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // MainPerson
  2. import java.util.ArrayList;
  3. public class MainPerson{
  4.   public static void main(String[] args) {
  5.     /*Add to List*/
  6.         Person p = new Person();
  7.      p.setName("Guita");
  8.         p.setAge(22);
  9.         System.out.println("-- Person --");
  10.      p.printDetails();
  11.      Teacher t = new Teacher("Khunpiny",22,"Coe");
  12.      t.setFaculty("CoE");
  13.         System.out.println("-- Teacher --");
  14.         System.out.println(t.getName()+" " + t.getAge() +" " + t.getFaculty());
  15.         Employee e = new Employee("Bow_e",22,"57_062");
  16.      e.setemployeeId("5735512062");
  17.         System.out.println("-- Employee --");
  18.      System.out.println(e.getName()+" " + e.getAge() +" " + e.getemployeeId());
  19.         ContractEmployee c = new ContractEmployee("Sirirat",22,"57_148",30000);
  20.      c.setConsalary(50000);
  21.         System.out.println("-- ContractEmployee --");
  22.      System.out.println(c.getName()+" " + c.getAge() +" " + c.getemployeeId() +" " + c.getConsalary());
  23.         PermanentEmployee per = new PermanentEmployee("Aunyamane",22,"57_149",30000);
  24.         per.setPersalary(45000);
  25.         System.out.println("-- PermanentEmployee --");
  26.         System.out.println(per.getName()+" " + per.getAge() +" " + per.getemployeeId() +" " + per.getPersalary());
  27.       System.out.println("-- ----------------- --");
  28.      ArraylistPerson p1 = new ArraylistPerson();
  29.         p1.addPerson(p);
  30.      p1.addPerson(t);
  31.         p1.addPerson(e);
  32.      p1.addPerson(per);
  33.      p1.addPerson(c);
  34.      p1.list();
  35.   }
  36. }
  37. // Person
  38.     public class Person {
  39.         private String name;
  40.         private int age;
  41.      public Person(){
  42.      }
  43.      public Person(String n, int a){
  44.             name = n;
  45.             age = a;
  46.     }
  47.     public void printDetails () {
  48.                 System.out.println("Name: " + name);
  49.             System.out.println("Age: " + age);
  50.      }
  51.      public String getName(){
  52.             return name;
  53.         }
  54.      public void setName(String n){
  55.             this.name = n;
  56.      }
  57.      public int getAge(){
  58.             return age;
  59.      }
  60.         public void setAge(int a){
  61.              this.age = a;
  62.       }
  63.         public String getFaculty() {  
  64.             return "";
  65.         }
  66.         public String getemployeeId() {  
  67.         return "";
  68.      }
  69.          public int getPersalary(){  
  70.             return 0;
  71.      }
  72.         public int getConsalary(){  
  73.             return 0;
  74.         }
  75. }
  76. //ArrayListPerson
  77. import java.util.ArrayList;
  78. public class ArraylistPerson{
  79.     private ArrayList<Person> items;
  80.      public ArraylistPerson(){  
  81.         items = new ArrayList<Person>();  
  82.   }
  83.   public void addPerson(Person theItem){  
  84.         items.add(theItem);
  85.   }
  86.   public void list()
  87.   {  
  88.         for(Person item : items){
  89.             if(item.getFaculty() != ""){
  90.                     System.out.print("Teacher : ");
  91.                  System.out.println(item.getName() +" "+ item.getAge() +" "+                    item.getFaculty());
  92.             }
  93.              else if((item.getFaculty() == "") &&item.getemployeeId() != "" &&          (item.getConsalary()== 0) && (item.getPersalary()==0)){
  94.                  System.out.print("Employee : ");
  95.                     System.out.println(item.getName() +" "+ item.getAge() +" "+                     item.getemployeeId() );
  96.          }
  97.              else if(item.getFaculty() == "" &&item.getemployeeId() != "" &&                (item.getPersalary()!= 0)){
  98.                     System.out.print("PermanentEmployee : ");
  99.                     System.out.println(item.getName() +" "+ item.getAge() +" "+ " "+                    item.getemployeeId()+" "  + item.getPersalary());
  100.          }
  101.              else if(item.getFaculty() == "" && (item.getConsalary()!= 0)){
  102.                     System.out.print("ContractEmployee : ");
  103.                     System.out.println(item.getName() +" "+ item.getAge() +" "+                     item.getemployeeId() +" "+ item.getConsalary());
  104.          }
  105.             else{
  106.                     System.out.print("Person : ");
  107.                  System.out.println(item.getName() +" "+ item.getAge());
  108.                  }
  109.          }
  110.     }
  111. }
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120. // Teacher
  121. public class Teacher extends Person{
  122.     private String faculty;
  123.     public Teacher(String name, int age,String f){
  124.      super(name, age);
  125.      faculty = f;
  126.     }
  127.     public String getFaculty(){  
  128.         return faculty;
  129.     }
  130.  
  131.    public void setFaculty (String f) {
  132.          faculty = f;
  133.     }
  134.  
  135. }
  136. // Employee
  137. public class Employee extends Person{
  138.    private String employeeId;
  139.     public Employee(String name, int age,String em){
  140.         super(name, age);
  141.         employeeId = em;
  142.    }
  143.     public String getemployeeId(){  
  144.          return employeeId;
  145.    }
  146.    public void setemployeeId (String em) {
  147.          employeeId = em;
  148.     }
  149. }
  150.  
  151.  
  152. // ContractEmployee
  153. public class ContractEmployee extends Employee{
  154.         private int payment;
  155.     public ContractEmployee(String name, int age,String em,int pay){
  156.         super(name, age,em);
  157.         payment = pay;
  158.     }
  159.     public int getConsalary(){  
  160.         return payment;
  161.     }
  162.    public void setConsalary (int pay) {
  163.          payment = pay;
  164.     }
  165. }
  166.  
  167.  
  168. // PermanentEmployee
  169. public class PermanentEmployee extends Employee{
  170.     private int salary;
  171.     public PermanentEmployee(String name, int age,String em,int salary){
  172.         super(name, age,em);
  173.         this.salary = salary;
  174.     }
  175.     public int getPersalary(){  
  176.         return this.salary;
  177.     }
  178.    public void setPersalary(int salary) {
  179.             this.salary = salary;
  180.     }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment