Hello,
I have a project that I am working on.
OK, I have to create an Employee class that has name and salary, a Manager class that inherits Employee with instance field department, and an Executive class that inherits Manager. In Manager class I have to provide a toString method that prints Manager's name, salary and department.
Actually, toString method is to be implemented for all classes. Then create 10 instances (Manager and Executive) of Employee. Create another method showReport(Employee emp) that prints out the details for each emp.
So far I got the following, but I am confused at where do I create a showReport() method? And am I doing OK so far? Thanks!
|
Code:
|
public class Employee
{
public String empName;
public int empSal;
public Employee()
{
}
public Employee(String myEmpName, int myEmpSal)
{
empName = myEmpName;
empSal = myEmpSal;
}
public String getEmpName()
{
return empName;
}
public int getEmpSal()
{
return empSal;
}
public String toString()
{
String s = "";
return "" + "Employee()" + "Name: " + this.getEmpName() + "Salary $" +
this.getEmpSal()+ "";
}
} |
|
Code:
|
public class Manager extends Employee
{
private String department;
public Manager()
{
}
public Manager(String name, int salary, String myDepartment)
{
super.empName = name;
super.empSal = salary;
this.department = myDepartment;
}
public String getDepartment()
{
return department;
}
public String toString()
{
String s = "";
return "Manager() " + "Name: " + super.getEmpName() + "\tDepartment: " + getDepartment();
}
} |
|
Code:
|
public class Executive extends Manager
{
public Executive()
{
}
public Executive(Manager mgr)
{
}
public String toString()
{
String s = "";
return "Executive() " + "Name: " + super.getEmpName() +"Department: " + super.getDepartment() + "";
}
} |
My tester class is not ready yet as I get a compilation error when I tried to create an instance of a Manager.
|
Code:
|
public class EmpTester
{
public static void main(String[] args)
{
Employee E1 = new Manager("Vlad", 500, 10);
}
} |