Advertisement
enkacang

Java_Class_2_Exersize

Feb 27th, 2023 (edited)
618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. class Employee
  4. {
  5.     int empId;
  6.     byte empAge;
  7.     char empCategory;
  8.     boolean isPermanent;
  9.     short companyNo;
  10.  
  11.     public Employee(int empId, byte empAge, char empCategory, boolean isPermanent, short companyNo) {
  12.         this.empId = empId;
  13.         this.empAge = empAge;
  14.         this.empCategory = empCategory;
  15.         this.isPermanent = isPermanent;
  16.         this.companyNo = companyNo;
  17.     }
  18.  
  19.     public byte getEmpAge() {
  20.         return empAge;
  21.     }
  22.  
  23.     public void setEmpAge(byte empAge) {
  24.         this.empAge = empAge;
  25.     }
  26.  
  27.     public char getEmpCategory() {
  28.         return empCategory;
  29.     }
  30.  
  31.     public void setEmpCategory(char empCategory) {
  32.         this.empCategory = empCategory;
  33.     }
  34.  
  35.     public boolean isPermanent() {
  36.         return isPermanent;
  37.     }
  38.  
  39.     public void setPermanent(boolean permanent) {
  40.         isPermanent = permanent;
  41.     }
  42.  
  43.     public short getCompanyNo() {
  44.         return companyNo;
  45.     }
  46.  
  47.     public void setCompanyNo(short companyNo) {
  48.         this.companyNo = companyNo;
  49.     }
  50.  
  51.     public int getEmpId() {
  52.         return empId;
  53.     }
  54.  
  55.     public void setEmpId(int empId) {
  56.         this.empId = empId;
  57.     }
  58.  
  59.     @Override
  60.     public String toString() {
  61.         return "Employee{" +
  62.                 "empId=" + empId +
  63.                 ", empAge=" + empAge +
  64.                 ", empCategory=" + empCategory +
  65.                 ", isPermanent=" + isPermanent +
  66.                 ", companyNo=" + companyNo +
  67.                 '}';
  68.     }
  69. }
  70.  
  71. public class Main {
  72.     public static void main(String[] args) {
  73.         Employee[] employees = new Employee[5];
  74.         Random random = new Random();
  75.  
  76.         for (int i = 0; i < employees.length; i++) {
  77.             int empId = i + 1;
  78.             byte empAge = (byte) (random.nextInt(50) + 20);
  79.             char empCategory = (char) ('A' + i);
  80.             boolean isPermanent = random.nextBoolean();
  81.             short companyNo = (short) (random.nextInt(1000) + 1);
  82.  
  83.             employees[i] = new Employee(empId, empAge, empCategory, isPermanent, companyNo);
  84.         }
  85.  
  86.         for (Employee employee : employees) {
  87.             System.out.println(employee.toString());
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement