Pages

Labels

A Corporation needs a program to calculate how much to pay to their hourly employees. The corporation requires that employee get paid time and a half for any hours over 35 that they work in a single week. For example if an employee work 42 hours, he get 7 hours overtime, at 1.5 times his base pay. The corporation requires that hourly employees be paid at least Rs.50 per hour. The corporation also requires that employee should not work more than 60 hours in a week. Write a program in Java which take base pay and no. of hours an employee works in a week as input, and compute the pay for hourly employee.

import java.util.*;
public class Salary
{
    public static void main(String [] args)
    {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter Base Pay of the employee in hours(base pay always > 50)");
        int basePay = input.nextInt();
        double pay=0;
        if(basePay<50)
        {
            System.out.println("Entered Wrong BasePay ");
            return;
        }
        System.out.println("Enter no. of hours he Worked in a week(hours always < 60) ");
        int hours = input.nextInt();
        if(hours>60||hours<0)
        {
            System.out.println("Entered Wrong no. of hours");
            return;
        }

        if(hours>0&&hours<=35)
        {
            pay = hours*basePay;
            System.out.println(" Pay = "+pay);
        }
        else
        {
            pay  = 35*basePay+(hours-35)*1.5*basePay;
            System.out.println(" Pay = "+pay);
        }
  }
}