Advertisement
kalin729

Kalin OOP TU Main

May 17th, 2022
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.49 KB | None | 0 0
  1. package kalin;
  2.  
  3. import java.math.BigDecimal;
  4. import java.util.ArrayList;
  5. import java.util.Scanner;
  6.  
  7. public class Test {
  8.  
  9.     public static void main(String[] args) {
  10.  
  11.         Scanner scanner = new Scanner(System.in);
  12.  
  13.         ArrayList<Employee> employees = new ArrayList<>();
  14.         ArrayList<Manager> managers = new ArrayList<>();
  15.  
  16.         int employeeCount = 3, managerCount = 2;
  17.  
  18.         for (int employeeNum = 0; employeeNum < employeeCount; employeeNum++) {
  19.             Employee employee = new Employee();
  20.  
  21.             System.out.println("Employee #" + (employeeNum + 1));
  22.             try {
  23.                 System.out.print("Employee number: ");
  24.                 employee.setNumber(Integer.parseInt(scanner.nextLine()));
  25.                 System.out.print("Employee name: ");
  26.                 employee.setName(scanner.nextLine());
  27.                 System.out.print("Employee salary: ");
  28.                 employee.setSalary(BigDecimal.valueOf(Double.parseDouble(scanner.nextLine())));
  29.                 employees.add(employee);
  30.             } catch (IllegalArgumentException exception) {
  31.                 System.out.println("Invalid input type.");
  32.                 System.out.println(exception.getMessage());
  33.                 employeeNum--;
  34.             }
  35.  
  36.         }
  37.  
  38.         for (int managerNum = 0; managerNum < managerCount; managerNum++) {
  39.             System.out.println("Manager #" + (managerNum + 1));
  40.  
  41.             try {
  42.                 Manager manager = new Manager();
  43.                 System.out.print("Manager number: ");
  44.                 manager.setNumber(Integer.parseInt(scanner.nextLine()));
  45.                 System.out.print("Manager name: ");
  46.                 manager.setName(scanner.nextLine());
  47.                 System.out.print("Manager salary: ");
  48.                 manager.setSalary(BigDecimal.valueOf(Double.parseDouble(scanner.nextLine())));
  49.                 System.out.print("Manager experience: ");
  50.                 manager.setExperience(Integer.parseInt(scanner.nextLine()));
  51.                 System.out.print("Manager addition: ");
  52.                 manager.setAddition(BigDecimal.valueOf(Double.parseDouble(scanner.nextLine())));
  53.                 managers.add(manager);
  54.             } catch (IllegalArgumentException exception) {
  55.                 System.out.println("Invalid input type.");
  56.                 System.out.println(exception.getMessage());
  57.             }
  58.  
  59.         }
  60.  
  61.         employees.forEach(System.out::println);
  62.         managers.forEach(System.out::println);
  63.  
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement