Search This Blog

UI/UX Design | Web Development | Mobile Application Development

Whether you need UI/ UX design, web development services, or mobile app development services, Qaabil Digitals will be more than happy to help you. We work with top software developers, designers, and project managers. We tailor our services to suit your exact needs. We closely look at your company, listen to your story, and bring about the best ideas and solutions that can help you drive solid results. We don’t just produce work that works. We produce work that matters. Get a quote now Or Talk to us

Wednesday, 21 September 2011

Java program to calculate salary of an employe using methods

import java.util.*;
class salary
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
double hpr,rh,oh;
System.out.print ("\n\t Enter hourly pay rate = ");
hpr=in.nextDouble();
System.out.print ("\n\t Enter regular hours = ");
rh=in.nextDouble();
System.out.print ("\n\t Enter overtime hours = ");
oh=in.nextDouble();

double rhp=0,otp,tp=0;
rhp = hpr*rh;                            //calculating regular hours pay: rhp

calculate ob = new calculate();            //creating object of class calculate
otp=ob.overtimepay(hpr,oh);                   //calling the method overtimepay
tp=rhp+otp;                                //calculating total pay

System.out.println ("\n\t Regular hours pay = "+rhp);
System.out.println ("\n\t Overtime pay = "+otp);
System.out.println ("\n\t Total pay = "+tp);
}
}


class calculate
{
double otp;
double overtimepay (double hpr, double oh)        //recieving hourly pay rate and overtime hours hpr, oh respectively
{
otp=(hpr*0.5)*oh;                                //calculating overtime pay
return otp;
}
}

1 comment:

  1. hello....i need the solution for= A worker normally works 40 hours a week. Excess overtime hours are paid 1.5 times the
    hourly rate, if the overtime hours are less than 10, 2 times if 10 to 20 hours inclusive, and 3
    times if over 20 hours.
    Write a program that asks the user to input number of hours worked for a week and hourly
    pay. Then calculate his salary.

    ReplyDelete

Share