platypus87 platypus87 - 3 months ago 10
Java Question

illegal start of expression in one, but not the other

I made a comment in the code where I am getting the illegal start off expression. I have annualSalary in the next class as well, but I am not getting the error and I cannot figure out why. The only difference is that the second one has another parameter. I have the two classes that I am using them in below. Thanks in advance!

public class Employee {

private String name;
private int monSal;
public double annSal;

public Employee(String name, int monSal) {

private double annualSalary(int monSal) { //illegal start of expression
annSal = monSal * 12;
return annSal;
}

public String toString(String name, int annSal) {
String empInfo = ("Emplyee name is: " + name + "and annual Salary is: \n" + annSal);
return empInfo;
}
}

private class Salesman extends Employee {

private int annSales;
private final double commission;

private Salesman(int annSales, String name, int monSal) {
super(name, monSal);
commission = annSales * .02;
}

private double annualSalary(int monSal, double commission) {
annSal = monSal * 12;

if (commission <= 20000) {
annSal = annSal + commission;
} else if (commission > 20000) {
annSal = annSal + 20000;
}
return annSal;
}

private String toString(String name, double annualSalary, double commission) {
String empInfo = ("Emplyee name is: " + name + "and annual Salary is: " + annualSalary + "and annual sales were: \n" + annSales);
return empInfo;
}
}

Answer

You didn't close your constructor.

public Employee(String name, int monSal) { } //Added a close brace

private double annualSalary(int monSal) {
    annSal = monSal * 12;
    return annSal;
}