I need help with this program in Java. Write a class named Employee that has the
ID: 3871288 • Letter: I
Question
I need help with this program in Java.
Write a class named 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.
Along with those fields, the class should have a method called print, which will print the fields of the class in a tab separated format, as follows: name idNumber department position Once you have the written the class, write a separate program that creates three Employee objects to hold the following data.
Name ID Number Department Position
------------------------------------------------------------------------------------
Susan Meyers 47899 Accounting Vice President
Mark Jones 39119 IT Programmer
Joy Rogers 81774 Manufacturing Engineer
The program should store this data in the three objects and then display the data for each employee on the screen exactly as shown in the table above.
Explanation / Answer
public class Employee {
private String name;
private int idNumber;
private String department;
private String position;
/**
* @param name
* @param idNumber
* @param department
* @param position
*/
public Employee(String name, int idNumber, String department,
String position) {
this.name = name;
this.idNumber = idNumber;
this.department = department;
this.position = position;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the idNumber
*/
public int getIdNumber() {
return idNumber;
}
/**
* @return the department
*/
public String getDepartment() {
return department;
}
/**
* @return the position
*/
public String getPosition() {
return position;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @param idNumber
* the idNumber to set
*/
public void setIdNumber(int idNumber) {
this.idNumber = idNumber;
}
/**
* @param department
* the department to set
*/
public void setDepartment(String department) {
this.department = department;
}
/**
* @param position
* the position to set
*/
public void setPosition(String position) {
this.position = position;
}
public void print() {
System.out.println(name + " " + idNumber + " " + department + " "
+ position);
}
}
public class TestEmployee {
public static void main(String[] args) {
Employee employee1 = new Employee("Susan Meyers", 47899, "Accounting",
"Vice President");
Employee employee2 = new Employee("Mark Jones", 39119, "IT",
"Programmer");
Employee employee3 = new Employee("Joy Rogers", 81774, "Manufacturing",
"Engineer");
System.out.println("Name ID Number Department Position");
System.out
.println("---------------------------------------------------");
employee1.print();
employee2.print();
employee3.print();
}
}
OUTPUT:
Name ID Number Department Position
---------------------------------------------------
Susan Meyers 47899 Accounting Vice President
Mark Jones 39119 IT Programmer
Joy Rogers 81774 Manufacturing Engineer