I hava below task. I stuck on the problem a). Create classes, which describe employees with hourly wage and fixed payment. Give your suggestions about relations between classes. Implement method for calculating the average monthly salary. For employees with hourly wage use next formula: “average monthly salary= 20.8*8* hourly rate”, for employees with fixed payment – “average monthly salary= fixed monthly payment”. Write well commented code for solving next problems a) Sort the collection of employees in descending order by the average monthly salary. In the case of equal salary – by the name. Write ID, name and monthly salary for all employees from collection. b) Write information about first five employees from collection (problem a). c) Write ID of three last employees from collection (problem b). d) Write code for reading and writing collection of these objects from (into) file. e) Write code for handling the incorrect format of incoming file.
I have created below classes, but I have no idea how to sort different objects from different classes. Please help me!!!!
import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
List<EmployeeFixedPayment> coll = new ArrayList<Employee>();
EmployeeHourlyWage a = new EmployeeHourlyWage("Edd", "Goo", 23, 4);
EmployeeHourlyWage b = new EmployeeHourlyWage("Tedd", "Foo", 2, 5);
EmployeeHourlyWage c = new EmployeeHourlyWage("Bob", "Bee", 4, 2);
EmployeeHourlyWage d = new EmployeeHourlyWage("Kate", "See", 2, 5);
EmployeeFixedPayment e = new EmployeeFixedPayment("Lisa", "Lee", 7, 500);
EmployeeFixedPayment f = new EmployeeFixedPayment("Mike", "Ree", 10,
450);
EmployeeFixedPayment g = new EmployeeFixedPayment("Izia", "Kurz", 13,
1000);
EmployeeFixedPayment j = new EmployeeFixedPayment("Aisha", "Moore", 20,
800);
coll.add(a);
coll.add(b);
coll.add(c);
coll.add(d);
coll.add(e);
coll.add(f);
coll.add(g);
coll.add(j);
Collections.sort(coll);
// System.out.println(coll.size());
for (Employee i : coll) {
System.out.print(i.secondName + " ");
}
}
}
public class Employee {
String firstName;
String secondName;
int id;
public Employee(String firstName, String secondName,int id){
this.firstName = firstName;
this.secondName = secondName;
this.id = id;
}
public void printEmployee(){
System.out.println(firstName+" "+secondName+" "+id);
}
public String getSecondName() {
return secondName;
}
public void setSecondName(String secondName) {
this.secondName = secondName;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
}
public class EmployeeFixedPayment extends Employee {
double fixedPayment;
public EmployeeFixedPayment(String firstName, String secondName, int id,
double salary) {
super(firstName, secondName, id);
fixedPayment = salary;
}
public double getSalary() {
return fixedPayment;
}
public void setSalary(double salary) {
fixedPayment = salary;
}
}
public class EmployeeHourlyWage extends Employee {
Double hourlyWage;
public EmployeeHourlyWage(String firstName, String secondName, int id, double hourlyRate) {
super(firstName, secondName, id);
hourlyWage = 20.8*8*hourlyRate;
}
public double getWage(){
return hourlyWage;
}
public void setWage(double rate) {
hourlyWage = 20.8*8*rate;
}
}