employees.txt Purpose: Build an application to calculatc an Fmploycc\'s Gross Pa
ID: 3732099 • Letter: E
Question
employees.txt
Explanation / Answer
import java.lang.*;
import java.io.*;
class Employee
{
String emp_id;
String emp_name;
String pay_period;
double hours_worked;
int hourlypay;
Employee (String id, String name, int hp, double hw )
{
emp_id=id;
emp_name=name;
hourlypay=hp;
hours_worked=hw;
}
void disp()
{
float gross_sal=(hours_worked * hp);
if (hours_worked>40)
{
double hw1= hours_worked – 40; //calculate extra hours worked
gross_sal= gross_sal + (hw1 * hp * 1.5);
}
System.out.println ("Employee Id= "+emp_id);
System.out.println ("Emplyee Name= "+emp_name);
System.out.println ("Gross Salary= "+gross_sal);
}
}
class Emp
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println ("Enter Emp id");
int id = Integer.parseInt(br.readLine());
System.out.println ("Enter Emp Name");
String name = br.readLine();
System.out.println ("Enter hourly pay and hours worked");
int hp = int.parseint(br.readLine());
double hw = double.parsedouble(br.readLine());
Employee obj= new Employee(id, name, hp, hw);
obj.disp();
}
}
ALGORITHM
Step 1: Read the employee id, employee name, hours worked, hourly pay from user.
Step 2: if hours worked is less than equal to 40 then calculate:
gross pay= hours_worked * hourly pay
Step 3: if hours_worked is greater than 40 calculate overtime hours and calculate
gross pay= gross pay + (overtime hours worked * hourly pay * 1.5)
Step 4: End.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.