Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package kalin;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Test {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- ArrayList<Employee> employees = new ArrayList<>();
- ArrayList<Manager> managers = new ArrayList<>();
- int employeeCount = 3, managerCount = 2;
- for (int employeeNum = 0; employeeNum < employeeCount; employeeNum++) {
- Employee employee = new Employee();
- System.out.println("Employee #" + (employeeNum + 1));
- try {
- System.out.print("Employee number: ");
- employee.setNumber(Integer.parseInt(scanner.nextLine()));
- System.out.print("Employee name: ");
- employee.setName(scanner.nextLine());
- System.out.print("Employee salary: ");
- employee.setSalary(BigDecimal.valueOf(Double.parseDouble(scanner.nextLine())));
- employees.add(employee);
- } catch (IllegalArgumentException exception) {
- System.out.println("Invalid input type.");
- System.out.println(exception.getMessage());
- employeeNum--;
- }
- }
- for (int managerNum = 0; managerNum < managerCount; managerNum++) {
- System.out.println("Manager #" + (managerNum + 1));
- try {
- Manager manager = new Manager();
- System.out.print("Manager number: ");
- manager.setNumber(Integer.parseInt(scanner.nextLine()));
- System.out.print("Manager name: ");
- manager.setName(scanner.nextLine());
- System.out.print("Manager salary: ");
- manager.setSalary(BigDecimal.valueOf(Double.parseDouble(scanner.nextLine())));
- System.out.print("Manager experience: ");
- manager.setExperience(Integer.parseInt(scanner.nextLine()));
- System.out.print("Manager addition: ");
- manager.setAddition(BigDecimal.valueOf(Double.parseDouble(scanner.nextLine())));
- managers.add(manager);
- } catch (IllegalArgumentException exception) {
- System.out.println("Invalid input type.");
- System.out.println(exception.getMessage());
- }
- }
- employees.forEach(System.out::println);
- managers.forEach(System.out::println);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement