Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am needing help with more testers for the Test class: Please include comments

ID: 3878040 • Letter: I

Question

I am needing help with more testers for the Test class: Please include comments as detailed as possible and see my below question about the Executive class.

Also, in the Executive class why is there a getter method but not a setter method? Does it need one and if so, please show me how. For the EmployeeTest class I just need more test programs for my classes- what I have is not sufficient and I am unsure what else to write in order to test everything as thorough as possible.

Codes:

Employee.java:

public class Employee {

private String name;

private double salary;

public Employee(String name, double salary) {

this.name = name;

this.salary = salary;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public double getSalary() {

return salary;

}

public void setSalary(double salary) {

this.salary = salary;

}

@Override

public String toString() {

return "Employee, Name=" + getName() + ", Salary=" + getSalary();

}

}

Manager.java:

public class Manager extends Employee {

private String department;

public Manager(String name, double salary, String department) {

super(name, salary);

this.department = department;

}

public String getDepartment() {

return department;

}

public void setDepartment(String department) {

this.department = department;

}

@Override

public String toString() {

return "Manager, Name=" + getName() + ", Salary=" + getSalary() + ",Department=" + getDepartment();

}

}

Executive.java:

public class Executive extends Manager {

private double bonusRatio;

public Executive(String name, double salary, String department,

double bonusRatio) {

super(name, salary, department);

this.bonusRatio = bonusRatio;

}

public double getSalary() {

return super.getSalary() * (1 + bonusRatio);

}

@Override

public String toString() {

return "Executive, Name=" + getName() + ", Salary=" + getSalary() + ",Department=" +getDepartment();

}

}

TestEmployees.java:

public class TestEmployees {

public static void main(String[] args) {

Employee dilbert = new Employee("Dilbert", 3000);

System.out.println(dilbert);

Employee pointyHairedBoss = new Manager("Dilbert Manager", 4000, "HR");

System.out.println(pointyHairedBoss );

Employee clueless = new Executive("Dilbert Executive", 5000, "Finance", 0.3);

System.out.println(clueless);

}

}

Explanation / Answer

Question .In the Executive class why is there a getter method but not a setter method?

Answer : There is no need of setter method in this class as this class extends to Employee class which is having setter method .So whenever you will create a new object of Executive class by calling its constructor

Executive(String name, double salary, String department,

double bonusRatio)

then the values of these attributes will set in super class which you cn get in child class.

I think you should not have setter methods in Employee and Manager Class as you are setting the values through constructor .

If you need these setters then you need to add default constructor in both the classes .

In my opinion most of the code is covered with your test cases .

I have added a few .Please check

Thanks

package employeetesting;

public class TestEmployees {

public static void main(String[] args) {

Employee dilbert = new Employee("Dilbert", 3000);

System.out.println(dilbert);

Employee pointyHairedBoss = new Manager("Dilbert Manager", 4000, "HR");

System.out.println(pointyHairedBoss );

Employee clueless = new Executive("Dilbert Executive", 5000, "Finance", 0.3);

System.out.println(clueless);


//You can test with negative values as well
Employee clue = new Executive("Dilbert Executive", -5000, "Finance", 0.3);

System.out.println(clue);
//you can check which class method clue will invoke
System.out.println(clue.getSalary()); //Note here Executive class method is invoked

}

}