Using Java, Create a class called Employee. It will have 3 attribute fields. Id
ID: 3807400 • Letter: U
Question
Using Java, Create a class called Employee. It will have 3 attribute fields. Id as integer, and name as String. It will have setter methods. It will have a showEmployeeInfoMethod() as a void.
Create a class called HourlyEmployee that extends the Employee class.
It will have int as hours and rate as double. It will have setter methods and a a showEmployeeInfo() as a void that will display the employee name and id along with the employee hours and rate and calculated salary as hours times rate in “correct money format”
Create 1 object called e1 in a class called EmployeeTester
You will pass any values you want using all setter methods.
You will display the information for the Employee
Explanation / Answer
package org.jay.chegg.march27;
import java.text.NumberFormat;
class Employee{
private int Id;
private String name;
/**
* @return the id
*/
public int getId() {
return Id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
Id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
public void showEmployeeInfo(){
}
}
class HourlyEmployee extends Employee{
private int hours;
private double rate;
/**
* @return the hours
*/
public int getHours() {
return hours;
}
/**
* @param hours the hours to set
*/
public void setHours(int hours) {
this.hours = hours;
}
/**
* @return the rate
*/
public double getRate() {
return rate;
}
/**
* @param rate the rate to set
*/
public void setRate(double rate) {
this.rate = rate;
}
/**
* Show employee info
*/
public void showEmployeeInfo(){
System.out.println("Name : "+this.getName());
System.out.println("Id : "+this.getId());
System.out.println("Total hours : "+hours);
System.out.println("Rate : "+rate+" per hour");
double salary=hours*rate;
NumberFormat formatter = NumberFormat.getCurrencyInstance();
System.out.println("Salary : "+formatter.format(salary));
}
}
public class EmployeeTester {
public static void main(String[] args) {
HourlyEmployee e1 = new HourlyEmployee(); // create hourlyemployee object
//setting the fields
e1.setName("Jack");
e1.setId(1);
e1.setHours(221);
e1.setRate(14.5);
//displaying the info
e1.showEmployeeInfo();
}
}
-------------------------------------------------------------------output-------------------------------------------------------------------
Name : Jack
Id : 1
Total hours : 221
Rate : 14.5 per hour
Salary : $3,204.50
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.