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

***Java*** Write a Java class named Employee that has the following fields: name

ID: 3574067 • Letter: #

Question

***Java***

Write a Java class named Employee that has the following fields:

name - The name field references a String object that hold's the employee's name

idNumber - The idNumber field is an int that hold's the employee's ID number

department - The department field references a String object that hold's the name of the department where the employee works

position - The position field references a String object that hold's the employee's job title

The class should have the following constructors:

A constructor that accepts the following values as arguments(parameters) and assigns them to the appropriate fields: employee's name, employee's ID number, department, and position.

A constructor that accepts the following values as arguments(parameters) and assigns them to the appropriate fields: employee's name, employee's ID number. The department and position fields should be assigned an empty String ("").

A default no argument constructor that assigns empty Strings ("") to the employee's name, department, and position fields, and 0 to the employee's ID number.

Write appropriate mutator methods that store values in theses fields and accessor methods that return the values in these fields. Please include the appropriate toString() method for this class as well. Once you have written the class, add a main method to it that creates three Employee objects to hold the following data:

The program should store this data in the three objects and then display (ie. output) the data for each employee.

Employee Name ID Number Department Position Susan Meyers 47899 Accounting Vice President Mark Jones 39119 IT Programmer Joy Rogers 81774 Manufacturing Engineer

Explanation / Answer

EmployeeTest.java


public class EmployeeTest {

   public static void main(String[] args) {
       Employee emp1 = new Employee("Susan Meyers",47899 , "Accounting","Vice President");
       Employee emp2 = new Employee("Mark Jones", 39119 );
       emp2.setPosition("IT Programmer");
       emp2.setDepartment("Computer Science");
       Employee emp3 = new Employee();
       emp3.setName("Joy Rogers");
       emp3.setIdNumber(81774 );

emp3.setDepartment("Mechanical");
       emp3.setPosition("Engineer");
       System.out.println("First employee details......");
       System.out.println(emp1.toString());
       System.out.println("Second employee details......");
       System.out.println(emp2.toString());
       System.out.println("Third employee details......");
       System.out.println(emp3.toString());      
   }

}

Employee.java


public class Employee {
   private String name;
   private int idNumber;
   private String department;
   private String position;
   public Employee(String name, int idNumber, String department, String position){
       this.name = name;
       this.idNumber = idNumber;
       this.department = department;
       this.position = position;
   }
   public Employee(String name, int idNumber){
       this.name = name;
       this.idNumber = idNumber;
       this.department = "";
       this.position = "";
   }
   public Employee(){
       this.name = "";
       this.idNumber = 0;
       this.department = "";
       this.position = "";
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public int getIdNumber() {
       return idNumber;
   }
   public void setIdNumber(int idNumber) {
       this.idNumber = idNumber;
   }
   public String getDepartment() {
       return department;
   }
   public void setDepartment(String department) {
       this.department = department;
   }
   public String getPosition() {
       return position;
   }
   public void setPosition(String position) {
       this.position = position;
   }  
   public String toString(){
       return "Employee Name: "+getName()+" ID Number: "+getIdNumber()+" Department: "+getDepartment()+" Position: "+getPosition();
   }
}

Output:

First employee details......
Employee Name: Susan Meyers ID Number: 47899 Department: Accounting Position: Vice President
Second employee details......
Employee Name: Mark Jones ID Number: 39119 Department: Computer Science Position: IT Programmer
Third employee details......
Employee Name: Joy Rogers ID Number: 81774 Department: Mechanical Position: Engineer