Question: Not compiling please help... public class lab7 { class Employee{ String name = name; int id; Employee(String name, int id){ this.id=id; this.name=name; } double getSalary(){//getSalary
Not compiling please help...
public class lab7 {
class Employee{
String name = "name";
int id;
Employee(String name, int id){
this.id=id;
this.name=name;
}
double getSalary(){//getSalary method must present in Employee class
return 0;
}
public String toString(){
return "Name: "+name+", Id: "+id;
}
}
class Full extends Employee{
double salary;
public Full(String name, int id, double salary){
super(name, id);
this.salary=salary;
}
double getSalary(){
return salary;
}
public String toString(){
return super.toString()+", Salary:"+salary;
}
}
class Part extends Employee{
double hours, hourlyWage;
public Part(String name, int id, double hours, double hourlyWage){
super(name, id);
this.hours = hours;
this.hourlyWage = hourlyWage;
}
double getSalary(){
return hours*hourlyWage;
}
public String toString(){
return super.toString()+", Hours: "+hours+", HourlyWage: "+hourlyWage;
}
}
class lab7 {
//create method creates objects for part and full classes and stores in employee array and returns number of objects stored in array.
public static int create(Employee employee[]){
int i = 0;
employee[i++] = new Part("John", 001, 10.0, 9.5);
employee[i++] = new Part("Kane", 002, 6.65, 8.3);
employee[i++] = new Full("Steven", 007, 50000);
employee[i++] = new Full("Cameron", 8, 65000);
return i;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
