Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Purpose: Build an application to calculate an Employee’s Gross Pay. Problem: Bui

ID: 3706717 • Letter: P

Question

Purpose: Build an application to calculate an Employee’s Gross Pay.

Problem: Build an application that would allow a person to calculate an Employee’s Gross Pay. The person will enter the employee’s name, regular hours worked, overtime hours worked and hourly pay rate.The program then calculates and displays the employee’s name and Gross Pay (see both inputs and outputs listed in the tables below).

Assumptions: Gross Pay = (Regular hours* pay rate) + (Over Time hours * pay rate *1.5) Regular hours are less than or equal to 40

Languages: Java, JDBC, MySQL Steps:

1) Create Employee Table in MySQL

2) Insert Data into Employee table (See Table #1 for Input data)

3) Read Data from Employee table and process in Java

4) Create in java a report (either on screen or in a file ie. Report.txt)

Data Requirements Fields Data-Type Input Employee Info First Name: Last Name: Hours Worked Pay Rate Strin String Double Currency or Double Processes Process Data to calculate Gross Pay Output (See Table #3 for output) Advanced Insert data using java code

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote