Answer on Question #70215 – Programming & Computer Science | Java | JSP | JSF
1. Exercise 71109 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 is a String object that holds the name of 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 the values in these fields and accessor methods that return the values in the field. Once you have written the class add a main method that creates three Employee objects to hold the following
data: Name ID Number Department Position
Susan Meyers 47899 Marketing Sales Rep
Mark Jones 39119 IT Programmer
Joy Rogers 81774 Manufacturing Engineer
The program should store this in the three objects and then display the data for each employee in the format:
Solution.
package com.company;
public class Employee {
private String name;
private int idNumber;
private String department;
private String position;
public Employee() {
}
public Employee(String name, int idNumber, String department, String position) {
this.name = name;
this.idNumber = idNumber;
this.department = department;
this.position = position;
}
public static void main(String[] args) {
Employee first = new Employee("Susan Meyers", 47899, "Marketing", "Sales Rep");
Employee second = new Employee("Mark Jones", 39119, "IT", "Programmer");
Employee third = new Employee("Joy Rogers", 81774, "Manufacturing", "Engineer");
System.out.println(first);
System.out.println(second);
System.out.println(third);
}
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;
}
@Override
public String toString() {
return String.format("data: %s %s %s %s", name, idNumber, department, position);
}
}Answer provided by www.AssignmentExpert.com