JAVA CODE REQUIRED MAKE A DUMMY FILE WHICH READS INPUT OF 4 EMPLOYEES Employee T
ID: 3804694 • Letter: J
Question
JAVA CODE REQUIRED
MAKE A DUMMY FILE WHICH READS INPUT OF 4 EMPLOYEES
Employee Types I. The company has three types of employees: the Hourly, Salary, and Commission types. Shown below describe each type of employee Salary Data Hourly Data Commission Data name name name employee number employee number employee number department department department 'H' 'S' type 'C' type type hourly pay rate number of weeks since yearly salary start of year or employment hours worked this week base weekly salary sales this week sales so far this year but not including this week commission rate Hourly Methods Salary Methods Commission Methods 1. ourly() Salary 0 Commission() 2. Hourly (all fields except Salary (all fields except Commission (tall fields type)) type)) except type and this week sales) 3. gets and sets for all data gets and sets for all data gets and sets for all data, but except type(no set, only get) except type(no set, only get) no set for sales for the year and for type(no set, only get) 4. double calcWeeklySalary O double calcWeeklySalary o double calcWeeklySalary 0 5. boolean equals (Employee e) boolean equals (Employee e) boolean equals (Employee e) boolean topSeller O String toString String toString 7. String toString 0 8. void writeData O void writeData o void write Data 0Explanation / Answer
Employee.java
--------------------------
package chegg;
public abstract class Employee {
private String name;
private int employeeNumber;
private String department;
public Employee(String name, int employeeNumber, String department) {
this.name = name;
this.employeeNumber = employeeNumber;
this.department = department;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getEmployeeNumber() {
return employeeNumber;
}
public void setEmployeeNumber(int employeeNumber) {
this.employeeNumber = employeeNumber;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
@Override
public String toString() {
return "Employee [name=" + name + ", employeeNumber=" + employeeNumber
+ ", department=" + department + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((department == null) ? 0 : department.hashCode());
result = prime * result + employeeNumber;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Employee other = (Employee) obj;
if (department == null) {
if (other.department != null)
return false;
} else if (!department.equals(other.department))
return false;
if (employeeNumber != other.employeeNumber)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}
HourlyDataEmployee.java
--------------------------------------
package chegg;
public class HourlyDataEmployee extends Employee {
private EmployeeEnum type;
private float houlrPerRate;
private int hourWorkForThisWeek;
HourlyDataEmployee(String name, int employeeNumber, String department) {
super(name, employeeNumber, department);
// TODO Auto-generated constructor stub
}
public HourlyDataEmployee(String name, int employeeNumber,
String department, float houlrPerRate, int hourWorkForThisWeek) {
super(name, employeeNumber, department);
this.houlrPerRate = houlrPerRate;
this.hourWorkForThisWeek = hourWorkForThisWeek;
this.type = EmployeeEnum.HOURLY;
}
public float getHoulrPerRate() {
return houlrPerRate;
}
public void setHoulrPerRate(float houlrPerRate) {
this.houlrPerRate = houlrPerRate;
}
public int getHourWorkForThisWeek() {
return hourWorkForThisWeek;
}
public void setHourWorkForThisWeek(int hourWorkForThisWeek) {
this.hourWorkForThisWeek = hourWorkForThisWeek;
}
public EmployeeEnum getType() {
return type;
}
@Override
public String toString() {
return "HourlyDataEmployee [type=" + type + ", houlrPerRate="
+ houlrPerRate + ", hourWorkForThisWeek=" + hourWorkForThisWeek
+ "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + Float.floatToIntBits(houlrPerRate);
result = prime * result + hourWorkForThisWeek;
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
public boolean equals(Employee obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
HourlyDataEmployee other = (HourlyDataEmployee) obj;
if (Float.floatToIntBits(houlrPerRate) != Float
.floatToIntBits(other.houlrPerRate))
return false;
if (hourWorkForThisWeek != other.hourWorkForThisWeek)
return false;
if (type != other.type)
return false;
return true;
}
public void writeData() {
}
}
SalaryDataEmployee.java
----------------------------------------
package chegg;
public class SalaryDataEmployee extends Employee {
private float yearlySalary;
private EmployeeEnum type;
public SalaryDataEmployee(String name, int employeeNumber, String department) {
super(name, employeeNumber, department);
}
public SalaryDataEmployee(String name, int employeeNumber,
String department, float yearlySalary) {
super(name, employeeNumber, department);
this.yearlySalary = yearlySalary;
this.type = EmployeeEnum.SALARY;
}
public float getYearlySalary() {
return yearlySalary;
}
public void setYearlySalary(float yearlySalary) {
this.yearlySalary = yearlySalary;
}
public EmployeeEnum getType() {
return type;
}
@Override
public String toString() {
return "SalaryDataEmployee [yearlySalary=" + yearlySalary + ", type="
+ type + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + Float.floatToIntBits(yearlySalary);
return result;
}
public boolean equals(Employee obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
SalaryDataEmployee other = (SalaryDataEmployee) obj;
if (type != other.type)
return false;
if (Float.floatToIntBits(yearlySalary) != Float
.floatToIntBits(other.yearlySalary))
return false;
return true;
}
public void writeData(){
}
}
CommissionDataEmployee .java
-------------------------------------------
package chegg;
public class CommissionDataEmployee extends Employee {
private int numberOfWeek;
private float baseWeekSalary;
private float salesThisWeek;
private float sales;
private float commissionRate;
private EmployeeEnum type;
public CommissionDataEmployee(String name, int employeeNumber, String department,
int numberOfWeek, float baseWeekSalary, float salesThisWeek,
float sales, float commissionRate) {
super(name, employeeNumber, department);
this.numberOfWeek = numberOfWeek;
this.baseWeekSalary = baseWeekSalary;
this.salesThisWeek = salesThisWeek;
this.sales = sales;
this.commissionRate = commissionRate;
this.type = EmployeeEnum.COMMISSION;
}
public CommissionDataEmployee(String name, int employeeNumber, String department) {
super(name, employeeNumber, department);
// TODO Auto-generated constructor stub
}
public int getNumberOfWeek() {
return numberOfWeek;
}
public void setNumberOfWeek(int numberOfWeek) {
this.numberOfWeek = numberOfWeek;
}
public float getBaseWeekSalary() {
return baseWeekSalary;
}
public void setBaseWeekSalary(float baseWeekSalary) {
this.baseWeekSalary = baseWeekSalary;
}
public float getSalesThisWeek() {
return salesThisWeek;
}
public void setSalesThisWeek(float salesThisWeek) {
this.salesThisWeek = salesThisWeek;
}
public float getSales() {
return sales;
}
public void setSales(float sales) {
this.sales = sales;
}
public float getCommissionRate() {
return commissionRate;
}
public void setCommissionRate(float commissionRate) {
this.commissionRate = commissionRate;
}
public EmployeeEnum getType() {
return type;
}
@Override
public String toString() {
return "CommissionData [numberOfWeek=" + numberOfWeek
+ ", baseWeekSalary=" + baseWeekSalary + ", salesThisWeek="
+ salesThisWeek + ", sales=" + sales + ", commissionRate="
+ commissionRate + ", type=" + type + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + Float.floatToIntBits(baseWeekSalary);
result = prime * result + Float.floatToIntBits(commissionRate);
result = prime * result + numberOfWeek;
result = prime * result + Float.floatToIntBits(sales);
result = prime * result + Float.floatToIntBits(salesThisWeek);
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
public boolean equals(Employee obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
CommissionDataEmployee other = (CommissionDataEmployee) obj;
if (Float.floatToIntBits(baseWeekSalary) != Float
.floatToIntBits(other.baseWeekSalary))
return false;
if (Float.floatToIntBits(commissionRate) != Float
.floatToIntBits(other.commissionRate))
return false;
if (numberOfWeek != other.numberOfWeek)
return false;
if (Float.floatToIntBits(sales) != Float.floatToIntBits(other.sales))
return false;
if (Float.floatToIntBits(salesThisWeek) != Float
.floatToIntBits(other.salesThisWeek))
return false;
if (type != other.type)
return false;
return true;
}
public void writeData() {
}
}
EmployeeEnum.java
------------------------------
package chegg;
public enum EmployeeEnum {
HOURLY(1, "HOURLY"), SALARY(2, "SALARY"), COMMISSION(3, "COMMISSION");
private int indx;
private String value;
EmployeeEnum(int indx, String value) {
this.indx = indx;
this.value = value;
}
public int getIndx() {
return indx;
}
public void setIndx(int indx) {
this.indx = indx;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.