Question: Create a Project Called : LabEmployee Add 2 files called: Employee.java EmployeeTest.java (UML Diagram) -------------------------------------------------------------- Employee --------------------------------------------------------------- - firstName : String - lastName : String
Create a Project Called : LabEmployee
Add 2 files called:
Employee.java
EmployeeTest.java
(UML Diagram)
--------------------------------------------------------------
Employee
---------------------------------------------------------------
- firstName : String
- lastName : String
- salary : Double
-----------------------------------------------------------------
<
+ getFirstName () : String
+ getLastName () : String
+ getSalary : Double
+ setSalary (s :Double)
---------------------------------------------------------------------
In Employee.java do the following:
1. Declare three private fields as described in the UML class diagram
2. Create a public constructor that initializes all three fields call the set accessor to initialize the field salary in the constructor
3. Create a get accessor for each of the fields
4. Create a set accessor for the field salary Inside of the set method do some input validation: check whether the parameter value is greater than or equal to 0. Only if that is the case the value is assigned to the private field salary. If the parameter value is less than 0 ignore the request (do nothing).
5. The fields firstName and lastName have no set method and cant be changed once they have been created
(What is the code for Employee.java?)
COMPLETED CODE FOR
EmployeeTest.java
public class EmployeeTest
{
public static void main(String[] args)
{
// create an instance of type Employee
Employee myEmployee = new Employee("John", "Smith", 1000);
// print the Employee data using get accessors
System.out.printf("myEmployee name: %s %s ",
myEmployee.getFirstName(), myEmployee.getLastName());
System.out.printf("myEmployee salary: $%.2f ", myEmployee.getSalary());
// attempt to change salary to an invalid value
myEmployee.setSalary(-500);
System.out.printf("myEmployee salary: $%.2f ", myEmployee.getSalary());
// change salary and display again
myEmployee.setSalary(1050);
System.out.printf("myEmployee salary: $%.2f ", myEmployee.getSalary());
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
