Design a class named Employee ( Employee.java ) to represent an employee. The cl
ID: 3908536 • Letter: D
Question
Design a class named Employee (
Employee.java
) to represent an employee. The class
contains:
?
Two private String data fields named
firstName
and
lastName
for the first name and
last name of the employee.
?
A private double data field named
monthlySalary
for the monthly salary of the
employee.
?
A public no-argument constructor that creates a default employee.
?
A public constructor that creates an employee with the specified
firstName
,
lastName
, and
monthlySalary
.
?
The public accessor and mutator methods for
firstName
,
lastName
, and
monthlySalary
.
Draw the UML diagram (
EmployeeUML.docx
) for the class and then implement the
class. Write a test program (
EmployeeTest.java
) that creates two Employee objects and
display each employee’s monthly salary and yearly salary. Then give each employee a
10% salary increase by invoking the
setMonthSalary()
method for each Employee
object and finally display each employee’s monthly salary and yearly salary again. The
output should look exactly like the following:
Before the 10% salary increase:
John Doe’s monthly salary is $3,000 and his yearly salary is $36,000.
Jane Doe’s monthly salary is $4,000 and her yearly salary is $48,000.
After the 10% salary increase:
John Doe’s monthly salary is $3,300 and his yearly salary is $39,600.
Jane Doe’s monthly salary is $4,400 and her yearly salary is $52,800.
Explanation / Answer
//Class structure definition of Employee.java is as below
public class Employee{
private String firstName,lastName;
private double monthlySalary;
public Employee(){
this.firstName = "Blank";
this.lastName = "Blank";
this.monthlySalary = 0.0;
}
public Employee(String first, String Last, double sal){
this.firstName = first;
this.lastName = Last;
this.monthlySalary = sal;
}
public void setFirstName(String first){
this.firstName = first;
}
public void setLastName(String last){
this.lastName = last;
}
public void setFirstName(double sal){
this.monthlySalary = sal;
}
public String getFirstName(){
return this.firstName;
}
public String getLastName(){
return this.lastName;
}
public double getMonthlySalary(){
return this.monthlySalary;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.