In: Computer Science
Develop a Java program that determines the gross pay for an employee. The company pays hourly rate for the first 40 hours worked by the employee and time and a half (1.5x hourly rate) for all hours worked in excess of 40. The user of your application will enter an employee name, shift (day or night) ,the number of hours worked for the week and their hourly rate. Your program should then calculate and display the employee’s name, regular pay, overtime pay, total gross pay and payperiod. PayPeriod is "Friday" for "day" shift and "Saturday" for "night" shift. Use class Scanner to input the data. Be sure to format output, so it is professionally displayed to your users.
Here is an example of pseudocode:
Start
Enter employee name
Enter employee shift (day/night)
Enter hours worked
Enter hourly pay rate
Calculate reg pay
if hours worked > 40 then
Calculate overtime pay
else
overtime = 0
Calculate total pay
Output employee name, reguldar pay, overtime pay, total pay
If day shift
output “Friday payperiod”
Else
output “Saturday payperiod”.
End.
package javaapplication1;
import java.util.Scanner;
/**
*
* @
*/
public class JavaApplication1 {
double Rpay=0, Opay=0;
void calPay(double hours, double rate){
if(hours<=40){
Rpay = hours * rate;
Opay = 0;
}
else {
double Rhr,Ohr;
Rhr = 40;
Ohr = hours-Rhr;
Rpay = Rhr * rate;
Opay = Ohr * (1.5*rate);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String name;
int shift;
Double rate, hours;
System.out.println("Hello Welcome To PAY CALCULATOR");
System.out.println("Please Enter Your Name");
name=sc.next();
System.out.println("Please Enter Your Shift, Please Enter 0 for
Day, 1 for Night");
System.out.println("0=Day, 1= Night");
shift=sc.nextInt();
System.out.println("Please Enter Number of Hours You Have
Worked");
hours=sc.nextDouble();
System.out.println("Please Enter Your Hourly Pay Rate");
rate=sc.nextDouble();
JavaApplication1 c= new JavaApplication1();
c.calPay(hours,rate);
Double Tpay= c.Rpay+ c.Opay;
System.out.println();
System.out.println("Calculating Pay");
System.out.println("Employee Name: "+name);
System.out.println("Employee Regular Pay: "+c.Rpay);
System.out.println("Employee Overtime Pay: "+c.Opay);
System.out.println("Employee Total Pay: "+Tpay);
if(shift==0){
System.out.println("Employee PayPeriod is Friday");
}
else{
System.out.println("Employee PayPeriod is Saturday");
}
}
}
Thanks and regards
if you like the answer please give a thumbs up
if you have a problem, feel free to comment.