Purpose: Build an application to calculate an Employee’s Gross Pay and a Departm
ID: 3878531 • Letter: P
Question
Purpose: Build an application to calculate an Employee’s Gross Pay and a Department’s Average Pay Report
Requirements: Build an application to allow the end-user to calculate an Employee’s Gross Pay and the Department’s average Gross Pay Report. First, the user will enter each employee’s name, hours worked and hourly pay rate into parallel arrays. Then the application calculates and displays each Employee’s Full Name and Payroll Information (see both inputs and outputs listed in the tables below).
Assumptions:
1. Assume your department has 10 employees (or less).
2. Gross Pay = (Regular hours* pay rate) + (Over Time hours * pay rate *1.5) a. Regular hours are less than or equal to 40 Language: JAVA Techniques: Your successful program will implement the following program techniques: 1. Arrays and Array Processing – (Arrays will hold employee information) 2. Methods – (Most of your process should be in methods)
3. Decisions – (Enter only hours worked – Your application calculates regular and overtime hours)
4. Loops – (For processing each employee)
Table 1- Data Requirements Data Requirements
Input Fields Data-Type Example Employee Info
First Name: String Joe
Last Name: String Smith
Regular Hours Worked Double 55.5
Pay Rate Currency or Double 12.50
Processes
Enter Employee’s Name
Enter Regular Hours
Enter Overtime Hours
Enter Pay Rate
Calculate Gross Pay
Output (output Format see below)
Employee’s Full Name
Hours
Pay Rate
Employee’s Gross Pay
Department Ave Pay
Advanced
Build in GUI
Table 2-Output Format
Name
Hours
Pay Rate
Gross Pay
Department Average
Explanation / Answer
import java.util.Scanner;
// Class GrossPay definition
public class GrossPay
{
// Instance variables to store employee information
String firstName;
String lastName;
double regularHours;
double overtimeHours;
double payRate;
double grossPay;
// Constructor to initialize instance variables
GrossPay()
{
firstName = lastName = "";
regularHours = overtimeHours = payRate = grossPay = 0.0;
}// End of constructor
// Method to accept employee data
void acceptData()
{
// Scanner class object created
Scanner sc = new Scanner(System.in);
// Accepts employee data from the user
System.out.println("Enter Employee’s First Name: ");
firstName = sc.next();
System.out.println("Enter Employee’s Last Name: ");
firstName = sc.next();
System.out.println("Enter Regular Hours: ");
regularHours = sc.nextDouble();
System.out.println("Enter Overtime Hours: ");
overtimeHours = sc.nextDouble();
System.out.println("Enter Pay Rate: ");
payRate = sc.nextDouble();
}// End of method
// Method to calculate gross pay
void processData()
{
grossPay = (regularHours * payRate) + (overtimeHours * payRate * 1.5);
}// End of method
// Method to display employees gross pay
void displayData()
{
System.out.println("Employee’s Full Name: " + firstName + " " + lastName);
System.out.println("Regular Hours: " + regularHours);
System.out.println("Overtime Hours: " + overtimeHours);
System.out.println("Pay Rate: " + payRate);
System.out.println("Employee’s Gross Pay: " + grossPay);
}// End of method
// main method definition
public static void main(String[] args)
{
// Initializes local variable to zero
double departmentAvgPay = 0.0;
// Creates an array of objects of class GrossPay of size 10
GrossPay gp[] = new GrossPay[10];
// Loops 10 times
for(int x = 0; x < 10; x++)
{
// Creates an object
gp[x] = new GrossPay();
// Calls the method to accept employees data
gp[x].acceptData();
// Calls the method to calculate employees gross salary
gp[x].processData();
// Calculates departments total pay
departmentAvgPay += gp[x].grossPay;
}// End of for loop
// Loops 10 times
for(int x = 0; x < 10; x++)
gp[x].displayData();
// Displays department average pay
System.out.println("Department Ave Pay: " + (departmentAvgPay / 10));
}// End of main method
}// End of class
Sample Run:
Enter Employee’s First Name:
Ram
Enter Employee’s Last Name:
Sahu
Enter Regular Hours:
10
Enter Overtime Hours:
2
Enter Pay Rate:
10
Enter Employee’s First Name:
Sita
Enter Employee’s Last Name:
Sahu
Enter Regular Hours:
12
Enter Overtime Hours:
3
Enter Pay Rate:
11
Enter Employee’s First Name:
Rakesh
Enter Employee’s Last Name:
Padhy
Enter Regular Hours:
22
Enter Overtime Hours:
1
Enter Pay Rate:
30
Enter Employee’s First Name:
Sarita
Enter Employee’s Last Name:
Swain
Enter Regular Hours:
12
Enter Overtime Hours:
3
Enter Pay Rate:
22
Enter Employee’s First Name:
Sunita
Enter Employee’s Last Name:
Panda
Enter Regular Hours:
11
Enter Overtime Hours:
3
Enter Pay Rate:
20
Enter Employee’s First Name:
Anita
Enter Employee’s Last Name:
Panda
Enter Regular Hours:
11
Enter Overtime Hours:
3
Enter Pay Rate:
11
Enter Employee’s First Name:
Anjana
Enter Employee’s Last Name:
Panda
Enter Regular Hours:
23
Enter Overtime Hours:
1
Enter Pay Rate:
20
Enter Employee’s First Name:
Dinku
Enter Employee’s Last Name:
Padhy
Enter Regular Hours:
22
Enter Overtime Hours:
3
Enter Pay Rate:
10
Enter Employee’s First Name:
Rahim
Enter Employee’s Last Name:
Sharma
Enter Regular Hours:
13
Enter Overtime Hours:
2
Enter Pay Rate:
30
Enter Employee’s First Name:
Binita
Enter Employee’s Last Name:
Panda
Enter Regular Hours:
11
Enter Overtime Hours:
2
Enter Pay Rate:
30
Employee’s Full Name: Sahu
Regular Hours: 10.0
Overtime Hours: 2.0
Pay Rate: 10.0
Employee’s Gross Pay: 130.0
Employee’s Full Name: Sahu
Regular Hours: 12.0
Overtime Hours: 3.0
Pay Rate: 11.0
Employee’s Gross Pay: 181.5
Employee’s Full Name: Padhy
Regular Hours: 22.0
Overtime Hours: 1.0
Pay Rate: 30.0
Employee’s Gross Pay: 705.0
Employee’s Full Name: Swain
Regular Hours: 12.0
Overtime Hours: 3.0
Pay Rate: 22.0
Employee’s Gross Pay: 363.0
Employee’s Full Name: Panda
Regular Hours: 11.0
Overtime Hours: 3.0
Pay Rate: 20.0
Employee’s Gross Pay: 310.0
Employee’s Full Name: Panda
Regular Hours: 11.0
Overtime Hours: 3.0
Pay Rate: 11.0
Employee’s Gross Pay: 170.5
Employee’s Full Name: Panda
Regular Hours: 23.0
Overtime Hours: 1.0
Pay Rate: 20.0
Employee’s Gross Pay: 490.0
Employee’s Full Name: Padhy
Regular Hours: 22.0
Overtime Hours: 3.0
Pay Rate: 10.0
Employee’s Gross Pay: 265.0
Employee’s Full Name: Sharma
Regular Hours: 13.0
Overtime Hours: 2.0
Pay Rate: 30.0
Employee’s Gross Pay: 480.0
Employee’s Full Name: Panda
Regular Hours: 11.0
Overtime Hours: 2.0
Pay Rate: 30.0
Employee’s Gross Pay: 420.0
Department Ave Pay: 351.5
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.