Not compiling please help!! public class lab7 { class Employee{ String name = \"
ID: 3702417 • 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;
}
//print method takes employee array and the number of objects stored and prints the employee details.
public static void print(Employee employee[], int n){
for(int i=0;i<n;i++)
System.out.println(employee[i].toString());
}
//highestSalary method prints the details of employee with highest salary.
public static void highest_salary(Employee employee[], int n){
double highest = employee[0].getSalary();
Employee highestSalary = employee[0];
for(int i=1;i<n;i++)
if(highest<employee[i].getSalary()){
highest = employee[i].getSalary();
highestSalary = employee[i];
}
System.out.println(" Employee with highest salary "+highestSalary.toString());
}
public static void main(String args[]){
Employee employee[] = new Employee[10];/*an array of Employee is created with size 10 is created, you can increase if you want to*/
int size = create(employee);
print(employee, size);
highest_salary(employee, size);
}
}
}
Explanation / Answer
public class lab7 { static class Employee{ String name = "name"; int id; double salary; 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; } } static 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; } } static 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; } } static class lab7Test { //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; } //print method takes employee array and the number of objects stored and prints the employee details. public static void print(Employee employee[], int n){ for(int i=0;iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.