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

Write a class called Employee based off of the following form: First Name: Last

ID: 3687496 • Letter: W

Question

Write a class called Employee based off of the following form:

First Name:

Last Name:

EmployeeID:

Email:

The first name, last name, and employee id should be stored in fields. The email should be computed via a method.

The email should be the first three letters of the first name followed by the first five letters of the last name followed by the last 2 digits of the 5 digit employee id followed by @hotmail.com.

The fields should all be private and each field should have get and set methods.

Next, write a Java application that instantiates three different Employee objects. Set the first name, last name, and id fields with data of your choosing. Call the method to set the email address for each employee. Finally, display the contents of all the fields of the three Employee objects.

Name the first class Employee with your last name added to the end of Employee.

Name the second class EmployeeTest with your last name at the end.

Explanation / Answer

/**
* @author Srinivas Palli
*
*/
public class EmployeeSrinivas {
   String firstName;
   String lastName;
   String employeeid;
   String email;

   /**
   * @return the firstName
   */
   public String getFirstName() {
       return firstName;
   }

   /**
   * @param firstName
   * the firstName to set
   */
   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }

   /**
   * @return the lastName
   */
   public String getLastName() {
       return lastName;
   }

   /**
   * @param lastName
   * the lastName to set
   */
   public void setLastName(String lastName) {
       this.lastName = lastName;
   }

   /**
   * @return the employeeid
   */
   public String getEmployeeid() {
       return employeeid;
   }

   /**
   * @param employeeid
   * the employeeid to set
   */
   public void setEmployeeid(String employeeid) {
       this.employeeid = employeeid;
   }

   /**
   * @return the email
   */
   public String getEmail() {
       return email;
   }

   /**
   * @param email
   * the email to set
   */
   public void setEmail() {

       String generatedEmail = "";
       // first three letters of the first name followed by the first five
       // letters of the last name followed by the last 2 digits of the 5 digit
       // employee id followed by @hotmail.com

       generatedEmail = firstName.substring(0, 3);
       generatedEmail += lastName.substring(0, 5);
       generatedEmail += employeeid.substring(employeeid.length() - 2,
               employeeid.length()) + "@hotmail.com";

       this.email = generatedEmail;

   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Employee [firstName=" + firstName + ", lastName=" + lastName
               + ", employeeid=" + employeeid + ", email=" + email + "]";
   }

}

/**
* @author Srinivas Palli
*
*/
public class EmployeeTestSrinivas {
   public static void main(String[] args) {
       EmployeeSrinivas employee1 = new EmployeeSrinivas();
       EmployeeSrinivas employee3 = new EmployeeSrinivas();
       EmployeeSrinivas employee2 = new EmployeeSrinivas();

       employee1.setFirstName("palli");
       employee1.setLastName("srinivas");
       employee1.setEmployeeid("123456");
       employee1.setEmail();
       System.out.println(employee1);

       employee2.setFirstName("pavan");
       employee2.setLastName("kumargourang");
       employee2.setEmployeeid("135781113");
       employee2.setEmail();
       System.out.println(employee2);

       employee3.setFirstName("rajesh");
       employee3.setLastName("kishorekumar");
       employee3.setEmployeeid("2468101214");
       employee3.setEmail();
       System.out.println(employee3);

   }
}

OUTPUT:

Employee [firstName=palli, lastName=srinivas, employeeid=123456, email=palsrini56@hotmail.com]
Employee [firstName=pavan, lastName=kumargourang, employeeid=135781113, email=pavkumar13@hotmail.com]
Employee [firstName=rajesh, lastName=kishorekumar, employeeid=2468101214, email=rajkisho14@hotmail.com]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote