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

Employee Class Write a class named Employee that has the following fields: name.

ID: 3911667 • Letter: E

Question

Employee Class Write a class named Employee that has the following fields: name. the name field references a String object that holds the employee’s name. idNumber. The idNumber is an int variable that holds the employee’s ID number. department. The department field references a String object that holds the name of the department where the employee works. positon. The position field references a String object that holds the employee’s job title. The class should have the following constructors: A constructor that accepts the following values as arguments 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 and assigns them to the appropriate fields: employee’s name and ID number. The department and position fields should be assigned an empty string (“”). A no-arg constructor that assigns empty strings (“”) to the name, department, and position fields, and 0 to the idNumber field. Write the appropriate mutator methods (also called setters) that store values in these fields and accessor methods (getters) that return the values in these fields. Once you have written the class, write a separate program that creates three Employee objects to hold the following data: Name ID Number Department Position Susan Myers 47899 Accounting Vice President Mark Jones 39119 IT Programmer Joy Rogers 81774 Manufacturing Engineer The program should use each of the three constructors (a different one for each case) to build and store this data in three Employee objects, and then display the data for each employee on the screen. Output should look like the following: Employee #1 Name: Susan Meyers ID Number: 47899 Department: Accounting Position: Vice President Employee #2 Name: Mark Jones ID Number: 39119 Department: IT Position: Programmer Employee #3 Name: Joy Rogers ID Number: 81774 Department: Manufacturing Position: Engineer Press any key to continue . . .

Explanation / Answer

/*
Employee class implementation comprising
3 Constructors as required
Getter methods
and settor methods
*/
class employee{

public String name;
public int idNumber;
public String department;
public String position;
  
employee(String name, int idNumber, String department, String position)
{
  
this.name = name;
this.idNumber = idNumber ;
this.department = department;
this.position = position;
}
  
employee(String name, int idNumber)
{
this.name = name;
this.idNumber = idNumber ;
this.department = "";
this.position = "";
}
  
employee()
{
this.name = "";
this.idNumber = 0;
this.department = "";
this.position = "";
}
  
/*
SETTER METHODS
*/

public void setName(String str)
{
name = str;
}
public void setIdNumber(int id)
{
idNumber = id;
}
public void setDepartment(String dept)
{
department = dept;
}
public void setPosition(String pos)
{
position = pos;
}
  
/*
GETTER METHODS
*/
  
public String getName()
{
return name;
}
public int getIdNumber()
{
return idNumber;
}
public String getDepartment()
{
return department;
}
public String getPosition()
{
return position;
}
  
  
}

/*
class of another program as required
to use the employee class constructors
and setter and getter methods for
data assignment + data retriving
*/

public class employeeData
{
public static void main(String[] args)
{
/*
Creating three objects to store three employee datas.
here calling the proper constructors as per employee data.
*/
employee e1 = new employee("Susan Myers" ,47899, "Accounting", "Vice President");
  
employee e2 = new employee("Mark Jones", 39119, "IT" ,"Programmer");
  
employee e3 = new employee("Joy Rogers", 81774, "Manufacturing", "Engineer");
  
/*
using setter methods to initialize variables
of above implemented employee class
*/
  
e1.setName("Susan Myers");
e1.setIdNumber(47899);
e1.setDepartment("Accounting");
e1.setPosition("Vice President");
  
e2.setName("Mark Jones");
e2.setIdNumber(39119);
e2.setDepartment("IT");
e2.setPosition("Programmer");
  
e3.setName("Joy Rogers");
e3.setIdNumber(81774);
e3.setDepartment("Manufacturing");
e3.setPosition("Engineer");
  
/*
Printing the employee information as required using the setter
method
*/
System.out.println("Employee #1 " + "Name: " + e1.getName() + " ID Number: " + e1.getIdNumber() + " Department: " + e1.getDepartment() + " Position: " + e1.getPosition() );
  
System.out.println("Employee #2 " + "Name: " + e2.getName() + " ID Number: " + e2.getIdNumber() + " Department: " + e2.getDepartment() + " Position: " + e2.getPosition() );
  
System.out.println("Employee #3 " + "Name: " + e3.getName() + " ID Number: " + e3.getIdNumber() + " Department: " + e3.getDepartment() + " Position: " + e3.getPosition() );
}
}

/*

MY OUTPUT OBTAINED

  

*/  

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