64 609
Assignments Done
99,1%
Successfully Done
In September 2018

Answer to Question #70518 in Java | JSP | JSF for Atif Haroon

Question #70518
(Employee Class) Create a class called Employee that includes three instance variablesa first name
(type String ), a last name (type String ) and a monthly salary ( double ). Provide a constructor
1
that initializes the three instance variables. Provide a set and a get method for each instance
variable. If the monthly salary is not positive, do not set its value. Write a test application named
EmployeeTest that demonstrates class Employee s capabilities. Create two Employee objects and
display each objects yearly salary. Then give each Employee a 10% raise and display each Employee
s yearly salary again
Expert's answer
Class Employee
public class Employee {
private String firstName;
private String lastName;
private double monthlySalary;
public Employee(String firstName, String lastName, double
monthlySalary) {
this.firstName = firstName;
this.lastName = lastName;
setMonthlySalary(monthlySalary);
}
public double getMonthlySalary() {
return monthlySalary;
}
public void setMonthlySalary(double monthlySalary) {
if (monthlySalary >= 0) {
this.monthlySalary = monthlySalary;
}
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Override
public String toString() {
return "first name:\t" + firstName + "\tlast name\t";
}
}
Class EmployeeTest
public class EmployeeTest {
public static void main(String[] args) {
Employee jackPerson = new Employee("Jack", "Pearson", 12000);
Employee luisLee = new Employee("Luis", "Lee", 25000);
System.out.println(jackPerson.toString() + "\t yearly salary\t" +
jackPerson.getMonthlySalary() * 12);
System.out.println(luisLee.toString() + "\t yearly salary\t" +
luisLee.getMonthlySalary() * 12);
jackPerson.setMonthlySalary(jackPerson.getMonthlySalary() +
jackPerson.getMonthlySalary() * 0.1);
luisLee.setMonthlySalary(luisLee.getMonthlySalary() +
luisLee.getMonthlySalary() * 0.1);
System.out.println(jackPerson.toString() + "\t yearly salary\t" +
jackPerson.getMonthlySalary() * 12);
System.out.println(luisLee.toString() + "\t yearly salary\t" +
luisLee.getMonthlySalary() * 12);
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions