emp Manager
unknown
plain_text
2 years ago
3.9 kB
1
Indexable
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package v01; /** * * @author MSI GTX */ public class Emp_Manager extends Employee { Employee emp = new Employee(); /** * Show Menu */ public void menu() { System.out.println("----------MENU----------"); System.out.println("1. Input employee."); System.out.println("2. Show list employee."); System.out.println("0. Exit."); System.out.print("Please choose: "); } /** * Show list of function. */ public void openMenu() { int func; do { menu(); func = checkInput(); switch (func) { case 1: add(); break; case 2: show(); break; case 0: System.out.println("SEE YOU AGAIN!"); return; } } while (func != 0); } /** * Check data when enter function * * @return */ public int checkInput() { while (true) { try { int result = Integer.parseInt(sc.nextLine().trim()); if (result < 0 || result > 2) { throw new NumberFormatException(); } return result; } catch (NumberFormatException e) { System.out.println("Please input number in rage [0-2]"); System.out.print("Enter again: "); } } } /** * Check data when enter number * * @return */ public int checkNumber() { int result = 0; do { try { result = Integer.parseInt(sc.nextLine()); if (result <= 0) { throw new NumberFormatException(); } } catch (NumberFormatException e) { System.out.println("--------Erorr! Please enter a number Employee greater than 0!"); System.out.print("Enter number of Employee: "); } } while (result <= 0); return result; } /** * Enter employee information. */ public void add() { System.out.print("Enter number of Employee: "); int empNum = checkNumber(); for (int i = 0; i < empNum; i++) { emp = new Employee(); System.out.println("Employee " + (i + 1) + ":"); while (true) { emp.inputID(); boolean IDExist = false; for (Employee empl : employee) { if (empl.getId().equals(emp.getId())) { IDExist = true; break; } } //Check if the ID exists if (IDExist) { System.out.println("--------Erorr: ID already exists!"); continue; } emp.input(); employee.add(emp); break; } } } /** * Show table information */ public void show() { if (employee.isEmpty()) { System.out.println("Empty list of employee!"); } else { System.out.println("======================= List Employee ======================="); System.out.printf("|ID |Name |Salary |COE |\n"); for (int i = 0; i < employee.size(); i++) { Employee e = employee.get(i); e.output(); } } } }
Editor is loading...