Hi Everyone,
I just need a little bit of help figuring out what i'm doing wrong in my code that the salary keeps output as zero. I'm writing a code that is suppose to determine whether the employee is a staff or faculty and then calculate and output the salary.
Below is my code:
Driver Class:
//driver class
public class DriverEmployee
{
public static void main(String[] args)
{
Faculty faculty1 = new Faculty("James", 1999);
Faculty faculty2 = new Faculty("Adam", 1997);
Faculty faculty3 = new Faculty("Judy", 2001);
Staff staff1 = new Staff("Tom", 1975);
Staff staff2 = new Staff("Frank", 1980);
System.out.println(faculty1.toString() + "\n" );
System.out.println(faculty2.toString() + "\n" );
System.out.println(faculty3.toString() + "\n" );
System.out.println(staff1.toString() + "\n");
System.out.println(staff2.toString() + "\n");
}
}
Super Class:
//super class
public class Employee
{
public String name;
//the year that the employee starts to work at mason
public int year;
//the boolean variable to determine if the person is a faculty
public boolean faculty;
public double rate;
public double salary;
public Employee(){}
public Employee(String empName, int yr)
{
this.name = empName;
this.year = yr;
}
public int getYear()
{
return this.year;
}
public String getName()
{
return this.name;
}
public double getSalary()
{
return this.salary;
}
public void setYear(int yr)
{
if(year > 1957)
year = yr;
}
public String toString()
{
return "Name: " + name + "\n Salary: $ " + salary;
}
public double getRate()
{
return salary;
}
}
Subclass:
//subclass
class Staff extends Employee
{
public Staff(){}
public Staff(String empName, int yr)
{
this.name = empName;
this.year = yr;
}
public double getRate()
{
salary = 5000*(Math.pow(1.03, (super.getYear()-1957)));
return salary;
}
}
Subclass:
//subclass
class Faculty extends Employee
{
public Faculty(){}
public Faculty(String empName, int yr)
{
this.name = empName;
this.year = yr;
}
public double getRate()
{
salary = 6000*(Math.pow(1.05, (super.getYear()-1957)));
return salary;
}
}