employee
unknown
plain_text
2 years ago
4.9 kB
7
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 */ import java.util.Scanner; /** * * @author MSI GTX */ public class Employee { private String id; private String name; private double salary; private double COE; /** * The constructor creates a new object Employee */ public Employee() { } /** * Gets the ID of employee * * @return */ public String getId() { return id; } /** * Sets the ID of employee * * @param id */ public void setId(String id) { this.id = id; } /** * Gets the name of employee * * @return */ public String getName() { return name; } /** * Sets the name of employee * * @param name */ public void setName(String name) { this.name = name; } /** * Gets the salary of employee * * @return */ public double getSalary() { return salary; } /** * Sets the salary of employee * * @param salary */ public void setSalary(double salary) { this.salary = salary; } /** * Gets the COE of employee * * @return */ public double getCOE() { return COE; } /** * Sets the COE of employee * * @param COE */ public void setCOE(double COE) { this.COE = COE; } /** * The constructor creates a new object Employee * * @param id * @param name * @param salary * @param COE * @throws Exception */ public Employee(String id, String name, double salary, double COE) throws Exception { this.id = id; this.name = name; this.salary = salary; this.COE = COE; } /** * Calculate the salary of employee * * @return */ public double calSalary() { return this.salary * this.COE; } /** * Take the input * */ public void input() { Scanner sc = new Scanner(System.in); //Check the ID of user's input until it's valid System.out.print("Please enter ID number: "); do { try { id = sc.nextLine().trim(); if (id.length() != 6 || id.charAt(0) != 'N' || id.charAt(1) != 'V') { System.out.print("--------Erorr! Please ID number again (NVxxxx): "); } } catch (Exception e) { System.out.print("--------Erorr! Please ID number again (NVxxxx): "); } } while (id.length() != 6 || id.charAt(0) != 'N' || id.charAt(1) != 'V'); //Check name of user's input until it's valid System.out.print("Please enter name: "); do { try { name = sc.nextLine().trim(); if (name.equals("")) { System.out.print("--------Erorr! Please name again (Not Null): "); } } catch (Exception e) { System.out.print("--------Erorr! Please name again (Not Null): "); } } while (name.equals("")); System.out.print("Please enter salary: "); //Validate the input. The salary must be great than 100. do { try { salary = Double.parseDouble(sc.nextLine()); if (salary <= 100) { System.out.print("--------Erorr! Please salary again (Salary > 100 USD): "); } } catch (NumberFormatException e) { System.out.print("--------Erorr! Please salary again (Salary > 100 USD): "); } } while (salary <= 100); System.out.print("--Please enter coefficients salary: "); //Validate the input. The COE must be from 1 to 5. do { try { COE = Double.parseDouble(sc.nextLine()); if (COE < 1 || COE > 5) { System.out.print("--------Erorr! Please coefficients salary again (From 1 to 5): "); } } catch (NumberFormatException e) { System.out.print("--------Erorr! Please coefficients salary again (From 1 to 5): "); } } while (COE < 1 || COE > 5); System.out.println("Save successfully!"); } /** * Display the output */ public void output() { System.out.printf("|%-12s|%-24s|%-16.0f|%-13.1f|\n", this.getId(), this.getName(), this.getSalary(), this.getCOE()); } }
Editor is loading...