SHARE
TWEET

04. Company Roster - 2

deyanmalinov Jun 5th, 2020 918 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package DPM;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Scanner;
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         int num = Integer.parseInt(scan.nextLine());
  9.         List<Employee> employees= new ArrayList<>();
  10.         for (int i = 0; i < num; i++) {
  11.             String[] line = scan.nextLine().split(" ");
  12.             String name = line[0];
  13.             double salary = Double.parseDouble(line[1]);
  14.             String position = line[2];
  15.             String department = line[3];
  16.             Employee employee=null;
  17.             switch (line.length){
  18.                 case 4:
  19.                     employee = new Employee(name, salary, position, department);
  20.                     break;
  21.                 case 5:
  22.                     if (line[4].matches("\\d+")){
  23.                         employee = new Employee(name, salary, position, department, Integer.parseInt(line[4]));
  24.                     }else {
  25.                         employee = new Employee(name, salary, position, department, line[4]);
  26.                     }
  27.                     break;
  28.                 case 6:
  29.                     employee = new Employee(name, salary, position, department,line[4], Integer.parseInt(line[5]));
  30.             }
  31.             employees.add(employee);
  32.         }
  33. //        TODO Printing
  34.     }
  35. }
  36. ---------------------------------------------------------------------
  37. package DPM;
  38. public class Employee {
  39.     private final static String NO_EMAIL = "n/a";
  40.     private final static int NO_AGE = -1;
  41.     private String name;
  42.     private double salary;
  43.     private String position;
  44.     private String department;
  45.     private String email;
  46.     private int age;
  47.     public Employee(String name, double salary, String position, String department) {
  48.         this(name, salary, position, department,NO_EMAIL, NO_AGE);
  49.     }
  50.     public Employee(String name, double salary, String position, String department, String email) {
  51.         this(name, salary, position, department, email, NO_AGE);
  52.     }
  53.     public Employee(String name, double salary, String position, String department, int age) {
  54.         this(name, salary, position, department, NO_EMAIL, age);
  55.     }
  56.     public Employee(String name, double salary, String position, String department, String email, int age) {
  57.         this.name = name;
  58.         this.salary = salary;
  59.         this.position = position;
  60.         this.department = department;
  61.         this.email=email;
  62.         this.age = age;
  63.     }
  64.     public String getDepartment() {
  65.         return department;
  66.     }
  67.     public double getSalary() {
  68.         return salary;
  69.     }
  70.     public String toString(){
  71.         return String.format("%s %.2f %s %d", this.name, this.salary, this.email, this.age);
  72.     }
  73. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top