Question: Write the java code (a) Write the code for an Employee class, which has the following fields: private String name; private double salary; Your class

Write the java code

(a) Write the code for an Employee class, which has the following fields:

private String name;

private double salary;

Your class should contain the following:

(i) Provide a constructor to set the employees name using a passed argument and also to set the salary to $0.

(ii) Provide a constructor that accepts arguments to set the employees name and salary. The salary should be set using the mutator method for salary described below.

(iii) Provide a mutator (i.e. setter) method for the salary that ensures the salary remains within the inclusive range $0 to $100,000. If an attempt is made to set a salary outside this range the current salary will not be changed.

(iv) Provide accessor (i.e. getter) methods for the name and for the salary.

(b) Write a program, called TestEmployee.java, to do the following:

(i) Create an employee object referenced by emp1, using the name Fred.

(ii) Assign a salary of $45,000 for employee Fred.

(iii) Create an employee object referenced by emp2, using the name Sue and assigns her a salary of $55,000, all in the one statement.

(iv) On a separate line for each employee, display the employees name and 40% of the salary, for taxation purposes.

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!