JAVA PROGRAMMING
Employee Class Write a class name Employee that has the following fields: · name. The name field is 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 is a string object that holds the name of the department where the employee works. · position. The position field is a string object that holds the employee’s job title. Write appropriate mutator methods that store values in these fields and accessor methods that return the values in these fields. Once you have the written the class, use the attached EmployeeDemo.java to test your Employee class. EmployeDemo will create 3 instances of the Employee class which will contain the following data.
Name ID Number Department Position Susan Myers 47899 Accounting Vice President Mark Jones 39119 IT Programming Joy Rogers 81774 Manufacturing Engineer
Copy the provide EmployeeDemo code to the chapter3 project.
public class EmployeeDemo
{
public static void main(String[] args)
{
// Create three instances of the Employee class.
Employee employee1 = new Employee();
Employee employee2 = new Employee();
Employee employee3 = new Employee();
// Store data for the first employee.
employee1.setName("Susan Meyers");
employee1.setIdNumber(47899);
employee1.setDepartment("Accounting");
employee1.setPosition("Vice President");
// Store data for the second employee.
employee2.setName("Mark Jones");
employee2.setIdNumber(39119);
employee2.setDepartment("IT");
employee2.setPosition("Programmer");
// Store data for the third employee.
employee3.setName("Joy Rogers");
employee3.setIdNumber(81774);
employee3.setDepartment("Manufacturing");
employee3.setPosition("Engineer");
// Display the data for employee 1.
System.out.println("Employee #1");
System.out.println("Name: " + employee1.getName());
System.out.println("ID Number: " + employee1.getIdNumber());
System.out.println("Department: " + employee1.getDepartment());
System.out.println("Position: " + employee1.getPosition());
System.out.println();
// Display the data for employee 2.
System.out.println("Employee #2");
System.out.println("Name: " + employee2.getName());
System.out.println("ID Number: " + employee2.getIdNumber());
System.out.println("Department: " + employee2.getDepartment());
System.out.println("Position: " + employee2.getPosition());
System.out.println();
// Display the data for employee 3.
System.out.println("Employee #3");
System.out.println("Name: " + employee3.getName());
System.out.println("ID Number: " + employee3.getIdNumber());
System.out.println("Department: " + employee3.getDepartment());
System.out.println("Position: " + employee3.getPosition());
System.out.println();
}
}
o Your Employee class should contain
Private variables private String name; // Employee's name private int idNumber; // ID number private String department; // Employee's department private String position; // Job title //you are not passing any arguments, so no constructor is required. setters and getters methods must be. setName //case matter here the N must be uppercase
setIdNumber setDepartment setPosition getName getNumber getDepartment getPosition
Expected Output 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