Question: Write a class named Employee that has the following fields / variables: name - The name field references a String object that holds the employee

Write a class named Employee that has the following fields/variables:
name - The name field references a String object that holds the employees name.
idNumber - The idNumber is an int variable that holds the employees ID number.
department - The department field references a String object that holds the name of the department where the employee works.
position - The position field references a String object that holds the employees job title.
salary - The salary is a double variable that holds the employee's monthly salary.
The class must have the following three constructors:
A constructor that accepts the following values as arguments and assigns them to the appropriate fields: employees name, employees ID number, department, position, and salary.
A constructor that accepts the following values as arguments and assigns them to the appropriate fields: employees name, ID number, and monthly salary. 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 and salary field.
Write appropriate mutator methods that store values in these fields and accessor methods that return the values in these fields. Once you have written the class, write a separate program(this part is given below) that creates three Employee objects to hold the following data: (data is in the table). The program should store this data in the three objects and then display the data for each employee on the screen. The main() function that creates these three objects is given below. Without modifying this given code, write a class named Employee that will work with this file:
/**
This main function is a partial a solution to the
Employee Class programming challenge. Do not change
this given code. You have to write your own Employee class.
*/
public class Main
{
public static void main(String[] args)
{
// Create the first employee. Use the no-arg constructor.
Employee employee1= new Employee();
employee1.setName("James Wilson");
employee1.setIdNumber(59512);
employee1.setDepartment("Accounting");
employee1.setPosition("Vice President");
employee1.setSalary(15000);
// Create the second employee. Use the constructor that accepts arguments for
// all of the fields.
Employee employee2= new Employee("Mary Garcia", 74536,"IT", "Programmer", 12000);
// Create the third employee. Use the constructor
// that accepts the name and ID number. Rest of the
// member variables need to be initialized by the
// third overloaded constructor
Employee employee3= new Employee("Robert Miller", 82654);
employee3.setDepartment("Manufacturing");
employee3.setPosition("Volunteer");
// 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("Yearly Salary: "+ employee1.getYearlySalary());
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("Yearly Salary: "+ employee2.getYearlySalary());
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("Yearly Salary: "+ employee3.getYearlySalary());
System.out.println();
}
}
Following is the exact output you should get:
Employee #1
Name: James Wilson
ID Number: 59512
Department: Accounting
Position: Vice President
Yearly Salary: 180000.0
Employee #2
Name: Mary Garcia
ID Number: 74536
Department: IT
Position: Programmer
Yearly Salary: 144000.0
Employee #3
Name: Robert Miller
ID Number: 82654
Department: Manufacturing
Position: Volunteer
Yearly Salary: 0.0
 Write a class named Employee that has the following fields/variables: name

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!