Not compiling please help... public class lab7 { class Employee{ String name = \
ID: 3702392 • Letter: N
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 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;
}
Explanation / Answer
1. Removed all compile time errors 2. Note: you have to write a driver class to test this lab7.java -------------------------------------------------------------- //lab7.java 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; } } public 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; } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.