Search This Blog

If you have any problem or question please write in the comments. We will try to solve and send you the solution. Not just that we will also post your problems solution on our blog.

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 (;
double hpr,rh,oh;
System.out.print ("\n\t Enter hourly pay rate = ");
System.out.print ("\n\t Enter regular hours = ");
System.out.print ("\n\t Enter overtime hours = ");

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;

No comments:

Post a Comment