Question
Write a class named Employee that has the following attributes (fields): name : The name attribute should be a String that holds an employee's first
Write a class named Employee that has the following attributes (fields):
name: The name attribute should be a String that holds an employee's first and last name
idNumber: The idNumber attribute is a String that holds an employee's ID number
department: The department attribute is a String that holds the name of the employee's department that they work in
position: The position attribute is a String that holds the name of the employee's job title
yearsWorked: The yearsWorked attribute holds the number of years the employee has worked at the company
The class should have the following overloaded constructors:
A constructor that accepts the following values as arguments and assigns them to the appropriate attributes (fields): employee?s name, employee?s ID number, employee's department, employee's position, and the number of years the employee has worked at the company.
o Do not allow the yearsWorked attribute to be set to values less than zero. If an attempt is made to set the yearsWorked attribute to less than zero, have your constructor set yearsWorked to zero.
A constructor that accepts the fallowing values as arguments and assigns them to the appropriate attributes (fields): employee?s name and employee's ID number. The department and positionattributes should be initialized to the empty string ("") and the yearsWorked attribute should be initialized to zero.
A default constructor (accepts no arguments) that initializes the name, idNumber, department, and position attributes to the empty string (""). The yearsWorked attribute should be initialized to zero.
Write Get and Set methods for each attribute: name, idNumber, department, position, and yearsWorked.
Do not allow the yearsWorked attribute to be set to values less than zero. If an attempt is made to set the yearsWorked attribute to less than zero, have your set method set yearsWorked to zero.
Next create a program named EmployeeTest.java to utilize the Employee class you created in the following manner. NOTE: This should be a short program... Only input the years worked for two of the objects: the ones that take only 2 values or no values (default constructor). The rest of the fields just use literals for constructors and/or the set methods ... so the program should not be more than about 30 lines maximum (it could be much less).:
1. Instantiate three Employee objects as follows:
Name | ID Number | Department | Position | Years Worked |
Jenny Jacobs | JJ8990 | Accounting | President | 15 |
Myron Smith | MS7571 | IT | Programmer | 5 |
Chris Raines | CR6873 | Manufacturing | Engineer | 30 |
Important: Use the constructor that takes everything for one of the employees (recommend Jenny), use the constructor that takes only name and id for another employee (recommend Myron), and use the constructor that takes nothing for the last employee (recommend Chris). Use set and get methods where needed.
Note: that will be three different objects with different constructors, each with its own employee.
2. Display the data for each of the three employees to the screen (you do not need to display the lines in the table)
Optional: In EmployeeTest, you can create a method that takes an Employee object and prints it if you wish. Makes it easier but purely optional.
Don?t forget to save your EmployeeTest.java file in the same directory as your Employee.java file that contains the Employee class.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started