Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Employee.java
- package employee;
- public class Employee {
- //Attributes
- //Main Attributes
- protected double salary;
- protected String firstName, middleName, lastName;
- //Support Attributes
- protected int daysWorked;
- protected double deduction;
- protected double dailyRate;
- protected int id;
- //Constructor
- public Employee(int id, String firstName, String middleName, String lastName) {
- this.id = id;
- this.firstName = firstName;
- this.middleName = middleName;
- this.lastName = lastName;
- }
- public Employee(int id, String firstName, String middleName, String lastName, double salary, int daysWorked, double dailyRate) {
- this.id = id;
- this.firstName = firstName;
- this.middleName = middleName;
- this.lastName = lastName;
- this.salary = salary;
- this.daysWorked = daysWorked;
- }
- //Getter Methods
- public double getSalary() {
- return salary;
- }
- public String getName() {
- return firstName + " " + middleName + " " + lastName;
- }
- public double getDeduction() {
- return deduction;
- }
- public int getID() {
- return id;
- }
- //Setter Methods
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
- public void setMiddleName(String middleName) {
- this.middleName = middleName;
- }
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
- public void setDaysWorked(int daysWorked) {
- this.daysWorked = daysWorked;
- }
- public void setID(int id) {
- this.id = id;
- }
- public void setDailyRate(double dailyRate) {
- this.dailyRate = dailyRate;
- }
- public void setNewSalary(double salary) {
- this.salary = salary;
- }
- //Display Method
- public String getInfo() {
- String fullName = this.getName();
- return String.format("%d\t|\t%s\t|\tPhp %.2f\t|\t%d\t|\tPhp %.2f\n", id, fullName, salary, daysWorked, dailyRate);
- }
- public String toString() {
- String fullName = this.getName();
- return String.format("%d\t|\t%s\t|\tPhp %.2f\t|\t%d\t|\tPhp %.2f\n", id, fullName, salary, daysWorked, dailyRate);
- }
- }
- //RegularEmployee.java
- package employee;
- public class RegularEmployee extends Employee{
- //Attributes
- //Main Attributes
- private double basicPay;
- private double overtimePay;
- //Support: Basic pay
- //Support: Overtime Pay
- private int overtimeHours;
- //Constructor
- public RegularEmployee(int id, String firstName, String middleName, String lastName) {
- super(id, firstName, middleName, lastName);
- }
- public RegularEmployee(int id, String firstName, String middleName, String lastName, double salary, int daysWorked, double dailyRate, int overtimeHours) {
- super(id, firstName, middleName, lastName, salary, daysWorked, dailyRate);
- this.overtimeHours = overtimeHours;
- }
- //Getter Methods
- @Override
- public double getSalary() {
- this.getBasicPay();
- this.getOvertimePay();
- salary = basicPay + overtimePay;
- if(daysWorked > 20) {
- this.getDeduction();
- salary -= deduction;
- }
- return salary;
- }
- private double getBasicPay() {
- basicPay = daysWorked * dailyRate;
- return basicPay;
- }
- private double getOvertimePay() {
- overtimePay = overtimeHours * (0.15 * dailyRate);
- return overtimePay;
- }
- @Override
- public double getDeduction() {
- deduction = dailyRate * 20;
- return deduction;
- }
- //Setter Methods
- public void setOvertimeHours(int overtimeHours) {
- this.overtimeHours = overtimeHours;
- }
- public void setSalary(double dailyRate, int daysWorked, int overtimeHours) {
- this.getBasicPay();
- this.getOvertimePay();
- salary = basicPay + overtimePay;
- if(daysWorked > 20) {
- this.getDeduction();
- salary -= deduction;
- }
- }
- }
- //ContractualEmployee.java
- package employee;
- public class ContractualEmployee extends Employee {
- //Attributes
- //Main Attributes
- //Support Attributes
- private final double deductionConstant = 1250;
- //Constructor
- public ContractualEmployee(int id, String firstName, String middleName, String lastName) {
- super(id, firstName, middleName, lastName);
- }
- public ContractualEmployee(int id, String firstName, String middleName, String lastName, double salary, int daysWorked, double dailyRate) {
- super(id, firstName, middleName, lastName, salary, daysWorked, dailyRate);
- }
- //Getter Methods
- @Override
- public double getSalary() {
- salary = daysWorked * dailyRate;
- if(daysWorked > 20) {
- this.getDeduction();
- salary -= deduction;
- }
- return salary;
- }
- @Override
- public double getDeduction() {
- deduction = deductionConstant;
- return deduction;
- }
- //Setter Methods
- public void setSalary(double dailyRate, int daysWorked) {
- salary = daysWorked * dailyRate;
- if(daysWorked > 20) {
- this.getDeduction();
- salary -= deduction;
- }
- }
- }
- //Runner.java
- package employee;
- import java.util.Scanner;
- import java.util.ArrayList;
- import java.util.InputMismatchException;
- public class Runner {
- public static void main(String[]args) {
- //Exit Variable
- boolean exit = false;
- //Employee Variables
- String name, firstName, middleName, lastName;
- int id = 0;
- int id2 = 0;
- //Scanner Object
- Scanner inputScanner = new Scanner(System.in);
- //Input Variable
- char input;
- int daysWorked = 0;
- int overtimeHours = 0;
- double dailyRate = 0;
- String nameInput;
- //Error Variable
- boolean errorMainMenu = false;
- //ArrayList
- ArrayList<RegularEmployee> regularEmployeeList = new ArrayList<RegularEmployee>();
- ArrayList<ContractualEmployee> contractualEmployeeList = new ArrayList<ContractualEmployee>();
- do {
- //Display
- System.out.println("Main Menu");
- System.out.println("1. New Employee");
- System.out.println("2. Employee List");
- System.out.println("3. Set Salary");
- System.out.println("4. Rename Employee");
- System.out.println("5. Remove Employee");
- System.out.println("6. Exit");
- //Scanner
- System.out.print("Input: ");
- input = inputScanner.next().charAt(0);
- //Exit
- switch(input) {
- case '1':
- boolean exitNewEmployee = false;
- //display
- do {
- System.out.println("Create New Employee");
- displayMenu();
- input = inputScanner.next().charAt(0);
- if (input == '1') {
- //Scanner
- Scanner nameScanner = new Scanner(System.in);
- //Name Input
- System.out.print("First Name Input: ");
- firstName = nameScanner.nextLine();
- System.out.print("Middle Name Input: ");
- middleName = nameScanner.nextLine();
- System.out.print("Last Name Input: ");
- lastName = nameScanner.nextLine();
- //Salary Input
- boolean correctInput = false;
- do {
- try {
- System.out.print("Days Worked Input: ");
- daysWorked = inputScanner.nextInt();
- System.out.print("Daily Rate Input: ");
- dailyRate = inputScanner.nextDouble();
- System.out.print("Overtime Hours Input: ");
- overtimeHours = inputScanner.nextInt();
- correctInput = true;
- } catch (InputMismatchException ime) {
- correctInput = false;
- }
- //ArrayList Creation
- regularEmployeeList.add(new RegularEmployee(id, firstName, middleName, lastName, 0, daysWorked, dailyRate, overtimeHours));
- regularEmployeeList.get(id).setDailyRate(dailyRate);
- double salary = regularEmployeeList.get(id).getSalary();
- regularEmployeeList.get(id).setNewSalary(salary);
- System.out.println("Regular Employee Created: " + id + " " + regularEmployeeList.get(id).getName());
- id++;
- }while(!correctInput);
- exitNewEmployee = true;
- }
- else if (input == '2'){
- //Scanner
- Scanner nameScanner = new Scanner(System.in);
- //Name Input
- System.out.print("First Name Input: ");
- firstName = nameScanner.nextLine();
- System.out.print("Middle Name Input: ");
- middleName = nameScanner.nextLine();
- System.out.print("Last Name Input: ");
- lastName = nameScanner.nextLine();
- //Salary Input
- boolean correctInput = false;
- do {
- try {
- System.out.print("Days Worked Input: ");
- daysWorked = inputScanner.nextInt();
- System.out.print("Daily Rate Input: ");
- dailyRate = inputScanner.nextDouble();
- correctInput = true;
- } catch (InputMismatchException ime) {
- correctInput = false;
- }
- //ArrayList Creation
- contractualEmployeeList.add(new ContractualEmployee(id2, firstName, middleName, lastName, 0, daysWorked, dailyRate));
- contractualEmployeeList.get(id2).setDailyRate(dailyRate);
- double salary = contractualEmployeeList.get(id2).getSalary();
- contractualEmployeeList.get(id2).setNewSalary(salary);
- System.out.println("Contractual Employee Created: " + id2 + " " + contractualEmployeeList.get(id2).getName());
- id2++;
- }while(!correctInput);
- exitNewEmployee = !exitNewEmployee;
- }
- else if (input == '3') {
- exitNewEmployee = !exitNewEmployee;
- }
- }while(!exitNewEmployee);
- break;
- case '2':
- boolean exitEmployeeList = false;
- //display
- do {
- System.out.println("Employee List");
- displayMenu();
- input = inputScanner.next().charAt(0);
- if (input == '1') {
- System.out.println("Listing all Regular Employees");
- displayOrder();
- try {
- for (int listEmployee = 0; listEmployee <= regularEmployeeList.size(); listEmployee++) {
- System.out.print(regularEmployeeList.get(listEmployee));
- }
- } catch (IndexOutOfBoundsException ioobe) {
- //System.out.println("Employees does not exist.");
- }
- exitEmployeeList = !exitEmployeeList;
- }
- else if (input == '2') {
- System.out.println("Listing all Contractual Employees");
- displayOrder();
- try {
- for (int listEmployee = 0; listEmployee <= contractualEmployeeList.size(); listEmployee++) {
- System.out.print(contractualEmployeeList.get(listEmployee));
- }
- } catch (IndexOutOfBoundsException ioobe) {
- //System.out.println("Employees does not exist.");
- }
- exitEmployeeList = !exitEmployeeList;
- }
- else if (input == '3') {
- exitEmployeeList = !exitEmployeeList;
- }
- }while(!exitEmployeeList);
- break;
- case '3':
- boolean exitSetSalary = false;
- do {
- System.out.println("Set Salary");
- displayMenu();
- input = inputScanner.next().charAt(0);
- if (input == '1') {
- System.out.println("Listing all Regular Employees");
- displayOrder();
- try {
- for (int listEmployee = 0; listEmployee <= regularEmployeeList.size(); listEmployee++) {
- System.out.print(regularEmployeeList.get(listEmployee));
- }
- } catch (IndexOutOfBoundsException ioobe) {
- //System.out.println("Employees does not exist.");
- }
- //Access ID
- int integerInput = 0;
- boolean correctInput = false;
- do {
- try {
- //Scanner
- Scanner accessScanner = new Scanner(System.in);
- //Input
- System.out.print("ID Input: ");
- integerInput = accessScanner.nextInt();
- correctInput = true;
- }
- catch (InputMismatchException ime) {
- correctInput = false;
- }
- }while(!correctInput);
- System.out.print("Accessing ");
- regularEmployeeList.get(integerInput).getName();
- System.out.print("\n");
- correctInput = !correctInput;
- do {
- try {
- System.out.print("Days Worked Input: ");
- daysWorked = inputScanner.nextInt();
- System.out.print("Daily Rate Input: ");
- dailyRate = inputScanner.nextDouble();
- System.out.print("Overtime Hours Input: ");
- overtimeHours = inputScanner.nextInt();
- correctInput = true;
- } catch (InputMismatchException ime) {
- correctInput = false;
- }
- }while(!correctInput);
- regularEmployeeList.get(integerInput).setDaysWorked(daysWorked);
- regularEmployeeList.get(integerInput).setDailyRate(dailyRate);
- regularEmployeeList.get(integerInput).setOvertimeHours(overtimeHours);
- regularEmployeeList.get(integerInput).setSalary(dailyRate, daysWorked, overtimeHours);
- System.out.println("New Salary Initialized");
- System.out.print(regularEmployeeList.get(integerInput).getInfo());
- exitSetSalary = !exitSetSalary;
- }
- else if (input == '2') {
- System.out.println("Listing all Contractual Employees");
- displayOrder();
- try {
- for (int listEmployee = 0; listEmployee <= contractualEmployeeList.size(); listEmployee++) {
- System.out.print(contractualEmployeeList.get(listEmployee));
- }
- } catch (IndexOutOfBoundsException ioobe) {
- //System.out.println("Employees does not exist.");
- }
- //Access ID
- int integerInput = 0;
- boolean correctInput = false;
- do {
- try {
- //Scanner
- Scanner accessScanner = new Scanner(System.in);
- //Input
- System.out.print("ID Input: ");
- integerInput = accessScanner.nextInt();
- correctInput = true;
- }
- catch (InputMismatchException ime) {
- correctInput = false;
- }
- }while(!correctInput);
- System.out.print("Accessing ");
- contractualEmployeeList.get(integerInput).getName();
- System.out.print("\n");
- correctInput = !correctInput;
- do {
- try {
- System.out.print("Days Worked Input: ");
- daysWorked = inputScanner.nextInt();
- System.out.print("Daily Rate Input: ");
- dailyRate = inputScanner.nextDouble();
- correctInput = true;
- } catch (InputMismatchException ime) {
- correctInput = false;
- }
- }while(!correctInput);
- contractualEmployeeList.get(integerInput).setDaysWorked(daysWorked);
- contractualEmployeeList.get(integerInput).setDailyRate(dailyRate);
- contractualEmployeeList.get(integerInput).setSalary(dailyRate, daysWorked);
- System.out.println("New Salary Initialized");
- System.out.print(contractualEmployeeList.get(integerInput).getInfo());
- exitSetSalary = !exitSetSalary;
- }
- }while(!exitSetSalary);
- break;
- case '4':
- boolean exitRenameEmployee = false;
- do {
- System.out.println("Rename Employee");
- displayMenu();
- input = inputScanner.next().charAt(0);
- if (input == '1') {
- System.out.println("Listing all regular employees");
- displayOrder();
- try {
- for (int listEmployee = 0; listEmployee <= regularEmployeeList.size(); listEmployee++) {
- System.out.print(regularEmployeeList.get(listEmployee));
- }
- } catch (IndexOutOfBoundsException ioobe) {
- //System.out.println("Employees does not exist.");
- }
- //Access ID
- int integerInput = 0;
- boolean correctInput = false;
- do {
- try {
- //Scanner
- Scanner accessScanner = new Scanner(System.in);
- //Input
- System.out.print("ID Input: ");
- integerInput = accessScanner.nextInt();
- correctInput = true;
- }
- catch (InputMismatchException ime) {
- correctInput = false;
- }
- }while(!correctInput);
- System.out.print("Accessing ");
- regularEmployeeList.get(integerInput).getName();
- System.out.print("\n");
- //Scanner
- Scanner nameScanner = new Scanner(System.in);
- //Name Input
- System.out.print("First Name Input: ");
- firstName = nameScanner.nextLine();
- System.out.print("Middle Name Input: ");
- middleName = nameScanner.nextLine();
- System.out.print("Last Name Input: ");
- lastName = nameScanner.nextLine();
- System.out.print("Successfully renamed " + regularEmployeeList.get(integerInput).getName());
- regularEmployeeList.get(integerInput).setFirstName(firstName);
- regularEmployeeList.get(integerInput).setMiddleName(middleName);
- regularEmployeeList.get(integerInput).setLastName(lastName);
- System.out.println(" to " + regularEmployeeList.get(integerInput).getName());
- exitRenameEmployee = !exitRenameEmployee;
- }
- else if (input == '2') {
- System.out.println("Listing all contractual employees");
- displayOrder();
- try {
- for (int listEmployee = 0; listEmployee <= contractualEmployeeList.size(); listEmployee++) {
- System.out.print(contractualEmployeeList.get(listEmployee));
- }
- } catch (IndexOutOfBoundsException ioobe) {
- //System.out.println("Employees does not exist.");
- }
- //Access ID
- int integerInput = 0;
- boolean correctInput = false;
- do {
- try {
- //Scanner
- Scanner accessScanner = new Scanner(System.in);
- //Input
- System.out.print("ID Input: ");
- integerInput = accessScanner.nextInt();
- correctInput = true;
- }
- catch (InputMismatchException ime) {
- correctInput = false;
- }
- }while(!correctInput);
- System.out.print("Accessing ");
- contractualEmployeeList.get(integerInput).getName();
- System.out.print("\n");
- //Scanner
- Scanner nameScanner = new Scanner(System.in);
- System.out.print("First Name Input: ");
- firstName = nameScanner.nextLine();
- System.out.print("Middle Name Input: ");
- middleName = nameScanner.nextLine();
- System.out.print("Last Name Input: ");
- lastName = nameScanner.nextLine();
- System.out.print("Successfully renamed " + contractualEmployeeList.get(integerInput).getName());
- contractualEmployeeList.get(integerInput).setFirstName(firstName);
- contractualEmployeeList.get(integerInput).setMiddleName(middleName);
- contractualEmployeeList.get(integerInput).setLastName(lastName);
- System.out.println(" to " + contractualEmployeeList.get(integerInput).getName());
- exitRenameEmployee = !exitRenameEmployee;
- }
- }while(!exitRenameEmployee);
- break;
- case '5':
- boolean exitRemoveEmployee = false;
- do {
- System.out.println("Remove Employee");
- displayMenu();
- input = inputScanner.next().charAt(0);
- if (input == '1') {
- System.out.println("Listing all regular employees");
- displayOrder();
- try {
- for (int listEmployee = 0; listEmployee <= regularEmployeeList.size(); listEmployee++) {
- System.out.print(regularEmployeeList.get(listEmployee));
- }
- } catch (IndexOutOfBoundsException ioobe) {
- //System.out.println("Employees does not exist.");
- }
- //Access ID
- int integerInput = 0;
- boolean correctInput = false;
- do {
- try {
- //Scanner
- Scanner accessScanner = new Scanner(System.in);
- //Input
- System.out.print("ID Input: ");
- integerInput = accessScanner.nextInt();
- correctInput = true;
- }
- catch (InputMismatchException ime) {
- correctInput = false;
- }
- }while(!correctInput);
- System.out.println("Removing regular employee, " + regularEmployeeList.get(integerInput).getName() + " , from the list.");
- regularEmployeeList.remove(integerInput);
- try {
- for(int i = 0; i <= regularEmployeeList.size(); i++) {
- regularEmployeeList.get(i).setID(i);
- }
- } catch(IndexOutOfBoundsException ioobe) {
- }
- exitRemoveEmployee = !exitRemoveEmployee;
- }
- else if (input == '2') {
- System.out.println("Listing all contractual employees");
- displayOrder();
- try {
- for (int listEmployee = 0; listEmployee <= contractualEmployeeList.size(); listEmployee++) {
- System.out.print(contractualEmployeeList.get(listEmployee));
- }
- } catch (IndexOutOfBoundsException ioobe) {
- //System.out.println("Employees does not exist.");
- }
- //Access ID
- int integerInput = 0;
- boolean correctInput = false;
- do {
- try {
- //Scanner
- Scanner accessScanner = new Scanner(System.in);
- //Input
- System.out.print("ID Input: ");
- integerInput = accessScanner.nextInt();
- correctInput = true;
- }
- catch (InputMismatchException ime) {
- correctInput = false;
- }
- }while(!correctInput);
- System.out.println("Removing contractual employee, " + contractualEmployeeList.get(integerInput).getName() + " , from the list.");
- contractualEmployeeList.remove(integerInput);
- try {
- for(int i = 0; i <= contractualEmployeeList.size(); i++) {
- contractualEmployeeList.get(i).setID(i);
- }
- } catch (IndexOutOfBoundsException ioobe) {
- }
- exitRemoveEmployee = !exitRemoveEmployee;
- }
- }while(!exitRemoveEmployee);
- break;
- case '6':
- exit = true;
- break;
- default:
- break;
- }
- }while(!exit);
- }
- public static void displayMenu() {
- System.out.println("1. Regular Employee");
- System.out.println("2. Contractual Employee");
- System.out.println("3. Return");
- System.out.print("Input: ");
- }
- public static void displayOrder() {
- System.out.println("ID\t|\tEmployee Name\t|\tSalary\t|\tDaily Rate\t|\tDays Worked\t|\tDaily Rate");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement