In: Computer Science
Write a Java Program using the concept of objects and classes. Make sure you have two files Employee.java and EmployeeRunner.java. Use the template below for ease. (Please provide detailed explanation)
Class Employee
Class Variables:
Name
Work hour per week
Hourly payment
Class Methods:
- Get/Sets
- generateAnnualSalary(int:Duration of employment)
annual salary = Hourly payment * Work hours per week * 50
If the employee is working for more than 5 years,
10% added bonus
-void displayAnnualSalary ( )
before and after tax considering there’s an effective 25% tax
Class EmployeeRunner
main method
- Create an object of type Employee
- Prompt the user to insert name, work hour per week, hourly payment and duration of
employment in years
Java Program:
File: Employee.java
class Employee
{
private String name;
private int workHoursPerWeek;
private double hourlyPayment;
//Constructor
public Employee()
{
name = "";
workHoursPerWeek = 0;
hourlyPayment = 0.0;
}
//Arg Constructor
public Employee(String n, int hrs, double pay)
{
name = n;
workHoursPerWeek = hrs;
hourlyPayment = pay;
}
//Getter and Setter Methods
public String getName()
{
return name;
}
public void setName(String n)
{
name = n;
}
public int getWorkHoursPerWeek()
{
return workHoursPerWeek;
}
public void setWorkHoursPerWeek(int hrs)
{
workHoursPerWeek = hrs;
}
public double getHourlyPayment()
{
return hourlyPayment;
}
public void setHourlyPayment(double pay)
{
hourlyPayment = pay;
}
//Method that generates Annual Salary
public double generateAnnualSalary(int duration)
{
//Calculating annual salary
double annualSal = (hourlyPayment *
workHoursPerWeek * 50);
//Checking duration
if(duration > 5)
{
//Adding 10%
Bonus
annualSal =
annualSal + (annualSal * 0.10);
}
return annualSal;
}
//Annual Salary Display
public void displayAnnualSalary(double
annualSal)
{
System.out.printf("\nBefore Tax:
$%.2f \n", annualSal);
//Adding tax
double annualSalWithTax = annualSal
+ (annualSal*0.25);
System.out.printf("\nAfter Tax:
$%.2f \n", annualSalWithTax);
}
}
File: EmployeeRunner.java
import java.util.*;
class EmployeeRunner
{
//Main method
public static void main(String[] args)
{
//Create an object of type
Employee
Employee empObj = new
Employee();
//Scanner object
Scanner reader = new
Scanner(System.in);
//Prompting details from user
System.out.print("Enter Student
Name: ");
String name =
reader.nextLine();
System.out.print("Enter work hour
per week: ");
int hrs = reader.nextInt();
System.out.print("Enter hourly
payment: $");
double hourlyPay =
reader.nextDouble();
System.out.print("Enter duration of
employment in years: ");
int years = reader.nextInt();
//Assigning values
empObj.setName(name);
empObj.setWorkHoursPerWeek(hrs);
empObj.setHourlyPayment(hourlyPay);
//Generating Annual Salary
double annualSal =
empObj.generateAnnualSalary(years);
//Printing salary
empObj.displayAnnualSalary(annualSal);
//Closing reader
reader.close();
}
}
__________________________________________________________________________________________
Sample Run: