Thursday, 30 August 2012

Dinesh Ku. Aggarwal , 29714 , CODE- CSEL-10X

Question :
An employee gets paid (hours worked) × (basic pay), for each hour up
to 40 hours.
For every hour over 40, they get overtime = (basic pay) × 1.5. The
basic pay must not be less than the minimum wage ($8.00 an hour).
If it is, print an error.
If the number of hours is greater than 60, he is paid for 60 hours

Write a JAVA code to calculate for each of these employees:
Basic Pay Hours Worked
Employee 1 $7.50 35
Employee 2 $8.20 47
Employee 3 $10.00 73
Employee 4 $7.00 65.




Answer :
class Sal
{
double salary(double b,int h)
{
int i,j=0;
if(h<40)
{
j=h;
}
else if(h>40&&h<60)
{
i=h%40;
j=40;
}
else
{
i=20;
j=40;
}
double d=(j*b)+(i*1.5*b);
return d;
}
public static void main(String args[])
{
System.out.println("Enter the no. of emplyees for who you want to
calculate the salary");
int i=System.in.read();
for(int r=0;r<i;r++)
{
System.out.println("Enter the Basic Pay.");
double basic_pay=System.in.read();
if(basic_pay<8.0)
{
System.out.println("Basic Pay cannot be less than $8.00");
goto l;
}
System.out.println("Enter the no. of hours worked");
int hour=System.in.read();
double total_salary=salary(basic_pay,hour);
System.out.println("Total Salary of "+r+"th person is "+total_salary);
l:
}
}
}



Note : This program can be used to find the salaries of as many
persons according to the specified rules.

No comments:

Post a Comment

C Programming

  Table of Contents ​ About the Author 3 ​ Introduction 4 ​ Introduction to Computers 4 1. What is a Computer? 4 2. History...