pw_

employee

pw_
Mar 19th, 2020
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3.  
  4. public class Employee {
  5.  
  6.     int id;
  7.     int salary;
  8.     String position;
  9.  
  10.     public Employee(int salary, String position) {
  11.         this.salary = salary;
  12.         this.position = position;
  13.     }
  14.  
  15.     @Override
  16.     public String toString() {
  17.         return "(" + id + ") (" + position +") : "+ salary;
  18.     }
  19.  
  20.     public static void main(String[] args) {
  21.         List<Employee> employeeList = new ArrayList<>();
  22.         Employee employee1 = new Employee(8000, "Programmer");
  23.         Employee employee2 = new Employee(6000, "Programmer");
  24.         Employee employee3 = new Employee(9000, "Programmer");
  25.  
  26.         employeeList.add(employee1);
  27.         employeeList.add(employee2);
  28.         employeeList.add(employee3);
  29.  
  30.         for (Employee employee: employeeList) {
  31.             System.out.println(employee.toString());
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment