# Salary Calculator And Display Employee Salary in Java

(Salary Calculator) Develop a Java application that determines the gross pay for each of
three employees. The company pays straight time for the first 40 hours worked by each employee and time and a half for all hours worked in excess of 40. You’re given a list of the employees, their number of hours worked last week and their hourly rates. Your program should input this information for each employee, then determine and display the employee’s gross pay. Use class Scanner to input the data.

## Salary Calculator And Display Employee Salary in Java

SalaryCalculator.java

``````/*
*       Filename:  SalaryCalculator.java
*
*    Description:  Exercise 4.20 - Salary Calculator
*
*  @Author:  Bilal Tahir Khan Meo
*  Website: https://www.codeblah.com
*
* =====================================================================================
*/
public class SalaryCalculator{
private static double BASE_HOURS = 40.0;
private static double OVERTIME_RATE = 1.5;

private double hours, pay;

public void setHours(double hours){
this.hours = hours;
}
public void setHourlyPay(double pay){
this.pay = pay;
}
public double calculateGrossPay(){
return hours > 40 ?
(pay * BASE_HOURS) + ((pay * OVERTIME_RATE) * (hours - BASE_HOURS)) :
hours * pay;
}
}``````

SalaryCalculatorTest.java

``````/*
*       Filename:  SalaryCalculatorTest.java
*
*    Description:  Exercise 4.20 - Salary Calculator
*
*  @Author:  Bilal Tahir Khan Meo
*  Website: https://www.codeblah.com
*
* =====================================================================================
*/
import java.util.Scanner;

public class SalaryCalculatorTest{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
SalaryCalculator salaryCalc = new SalaryCalculator();

for(int i=1; i<4; i++){
System.out.printf("Employee %d weekly hours: ", i);
salaryCalc.setHours(sc.nextDouble());

System.out.printf("Employee %d hourly pay: ", i);
salaryCalc.setHourlyPay(sc.nextDouble());

System.out.printf("Employee %d gross pay: %.2f\n", i, salaryCalc.calculateGrossPay());
}
}
}``````