Skip to main content

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.

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);


        }




    }
}



Comments

Popular posts from this blog

Create a class called Book to represent a book. A Book should include four pieces of information as instance variables‐a book name, an ISBN number, an author name and a publisher. Your class should have a constructor that initializes the four instance variables. Provide a mutator method and accessor method (query method) for each instance variable. In addition, provide a method named getBookInfo that returns the description of the book as a String (the description should include all the information about the book). You should use this keyword in member methods and constructor. Write a test application named BookTest to create an array of object for 30 elements for class Book to demonstrate the class Book's capabilities.

Create a class called Book to represent a book. A Book should include four pieces of information as instance variables‐a book name, an ISBN number, an author name and a publisher. Your class should have a constructor that initializes the four instance variables. Provide a mutator method and accessor method (query method) for each instance variable. In addition, provide a method named getBookInfo that returns the description of the book as a String (the description should include all the information about the book). You should use this keyword in member methods and constructor. Write a test application named BookTest to create an array of object for 30 elements for class Book to demonstrate the class Book's capabilities. import java.io.*; class Book {     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));     String book_name;     int isbn;     String author;     String publisher; ...

Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables‐a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. In addition, provide a method named get Invoice Amount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as a double value. If the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to 0. Write a test application named InvoiceTest that demonstrates class Invoice’s capabilities.

Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables‐a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. In addition, provide a method named get Invoice Amount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as a double value. If the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to 0. Write a test application named InvoiceTest that demonstrates class Invoice’s capabilities. import java.io.*; class Invoice {     BufferedReader br = new BufferedReader(new InputStreamReader(System.i...

Create a class called Employee that includes three pieces of information as instance variables—a first name (type String), a last name (type String) and a monthly salary (double). Your class should have a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, set it to 0. Write a test application named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10% raise and display each Employee’s yearly salary again

Create a class called Employee that includes three pieces of information as instance variables—a first name (type String), a last name (type String) and a monthly salary (double). Your class should have a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, set it to 0. Write a test application named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10% raise and display each Employee’s yearly salary again . import java.io.*; class Employee {     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));     String f_name;     String l_name;     int sal;     Employee()     {         f_name="sarvajeet";     ...