The reason salary printed $0.00000 is because you've placed if statement for some reason instead of just setting salary you passed to constructor. Second thing, void methods does not return anything that's the reason raise method did not work the way you wanted. I fixed it for you so take a look, hopefully I helped you understand where you went wrong and if you have any questions feel free to ask I'm here for you.
Employee Test class:
public class EmployeeTest {
public static void main(String[] args) {
Employee raise1= new Employee("Betty","Jones",4000.0);
Employee raise2= new Employee("Sally","Mae",6000.0);
//Print statements for the employee's name and salary
System.out.printf("Employee #1\nFirst Name: %s\nLast Name: %s\n\n" +
"Salary: $%.2f",
raise1.getName(),
raise1.getLastName(),
raise1.getSalary());
System.out.printf("\nHer raise will be: $%.2f",
raise1.raise(raise1.getSalary()));
System.out.printf("\n\nEmployee #2\nFirst Name: %s\nLast Name: %s\n\n" +
"Salary: $%.2f",
raise2.getName(),
raise2.getLastName(),
raise2.getSalary());
System.out.printf("\nHer raise will be: $%.2f\n",
raise2.raise(raise2.getSalary()));
}
}
Employee class:
public class Employee {
//instance variable
private String name;
private String lastName;
private double salary;
//getters
public String getLastName() {
return lastName;
}
public String getName() {
return name;
}
public double getSalary() {
return salary;
}
public double raise(double raise){
salary = salary + (salary*.1);
return salary;
}
//constructor
public Employee(String name, String lastName, double salary){
this.name = name;
this.lastName = lastName;
this.salary = salary;
}
}
Print output from the program above:
Employee #1
First Name: Betty
Last Name: Jones
Salary: $4000.00
Her raise will be: $4400.00
Employee #2
First Name: Sally
Last Name: Mae
Salary: $6000.00
Her raise will be: $6600.00