Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please answer in basic pseudocode. -empID: String -firstName: String -lastName:

ID: 3918832 • Letter: P

Question

Please answer in basic pseudocode.

-empID: String

-firstName: String

-lastName: String

-payRate: Real

+Employee()

-SetEmpID(theID: String)

-SetFirstName(fName: String)

-SetLastName(lName: String)

-SetPayRate(testPay:Real)

-ValidString(testString: String, validMin:Integer, validLength:Integer, txtMSG:String):String

-ValidPay(pay:Real):Real

+DisplayEmployee():String

Create an employee class based on this UML class diagram.

The setters should prompt the user for the information to set the value of the instance variables. These are the validation rules:

The ID has to be 4 characters long. If it is invalid the characters XXXX have to replace the invalid ID.

The minimum length for a first or last name is 2 characters and the maximum length is 20 characters. If invalid the first or last name have to be replaced with XXXX.

The pay rate has to be between 0 and 1000000. If invalid the pay rate has to be replaced with 0.

Use the ValidString Function to validate the first name, last name and empID. The invalid message should include which item was incorrect. For example if the first name was incorrect it should display “Invalid first name. Set to XXXX”

The DisplayEmployee getter function should display all of the employee information.

Create a program that uses the Employee class to create an array of employee objects based on the user’s input. It should then display all of the employee data in the array.

Employee

-empID: String

-firstName: String

-lastName: String

-payRate: Real

+Employee()

-SetEmpID(theID: String)

-SetFirstName(fName: String)

-SetLastName(lName: String)

-SetPayRate(testPay:Real)

-ValidString(testString: String, validMin:Integer, validLength:Integer, txtMSG:String):String

-ValidPay(pay:Real):Real

+DisplayEmployee():String

Explanation / Answer

Since you have not mentioned the language of your preference, I am providing the code in Java.

CODE

==================

import java.util.Scanner;

public class Employee {

   private static final Scanner sc = new Scanner(System.in);

   private String empID, firstName, lastName;

   private double payRate;

  

   public Employee() {

       System.out.print("Enter the employee ID : ");

       setEmpID(sc.next());

      

       System.out.print("Enter the employee First Name : ");

       setFirstName(sc.next());

      

       System.out.print("Enter the employee Last Name : ");

       setLastName(sc.next());

      

       System.out.print("Enter the employee pay rate : ");

       setPayRate(sc.nextDouble());

   }

  

   public void setEmpID(String theID) {

       this.empID = validString(theID, 4, 4, "ID");

   }

  

   public void setFirstName(String fname) {

       this.firstName = validString(fname, 2, 20, "first name");

   }

  

   public void setLastName(String lname) {

       this.lastName = validString(lname, 2, 20, "first name");

   }

  

   public void setPayRate(double testPay) {

       this.payRate = validPay(testPay);

   }

  

   public String validString(String testString, int validMin, int validLength, String txtMessage) {

       if(testString.length() < validMin || testString.length() > validLength) {

           System.out.println("Invalid " + txtMessage +" . Set to XXXX.");

           return "XXXX";

       }

       return testString;

   }

  

   public double validPay(double pay) {

       if(pay < 0 || pay > 1000000)

           return 0;

       return pay;

   }

  

   public void displayEmployee() {

       System.out.println("The employee details are : ");

       System.out.println("ID : " + empID);

       System.out.println("First Name : "+ firstName);

       System.out.println("Last Name : " + lastName);

       System.out.println("Pay rate : " + payRate);

   }

  

   public static void main(String args[]) {

       Employee[] employees = new Employee[5];

       for(int i=0; i<5; i++) {

           System.out.println("Employee " + (i+1) + " : ");

           employees[i] = new Employee();

       }

      

       for(int i=0; i<5; i++) {

           employees[i].displayEmployee();

       }

   }

}