Question
Code a Java program that calculates gross pay of an employee, the smallest gross pay, the largest gross pay and total payroll for all employees
Code a Java program that calculates gross pay of an employee, the smallest gross pay, the largest gross pay and total payroll for all employees (must be separate functions) ex. calcGross, smallGross, largeGross, totalGross
Here's what I have so far:
import javax.swing.JOptionPane;
public class Employee { //declarations //Employee static String [] ssn = new String[100]; static double [] rate = new double[100]; static double [] hours = new double[100]; static double [] grossPay = new double[100]; //working variables static int selection = 0; static int EmpCount = 0; static String searchSSN = " "; static int foundAt = -1; // -1 means not found static double gross = 0;
public static void main(String[] args) { while(selection != 4) { menu(); switch(selection) { case 1: addEmployee(); EmpCount++; break; case 2: for (int i = 0; i < EmpCount; i++) dispEmployee(i); break; case 3: //ask user to enter the ssn to search for employee String input = " "; input = JOptionPane.showInputDialog("Enter the social security number of the student: " ); searchSSN = input; foundAt = searchEmployee(); //if found display this student, otherwise display message not found if(foundAt < 0) JOptionPane.showMessageDialog(null, "Student Not found!..."); else dispEmployee(foundAt); break; case 4: JOptionPane.showMessageDialog(null, "Thank you for using this application..."); break; default: JOptionPane.showMessageDialog(null, "Invalid selection!..."); break; }//end switch }//end while
}//end main //------------------------------------------------------------- public static void menu() { String input = " "; input = JOptionPane.showInputDialog("-1-Add a Employee " + "-2-Display all Employees " + "-3-Search for an employee " + "-4-Quit program " + " \t\tEnter selection"); selection = Integer.parseInt(input); }//end menu //-------------------------------------------------------------- public static void addEmployee() { String input = " "; input = JOptionPane.showInputDialog("Enter SSN: "); ssn[EmpCount] = input; input = JOptionPane.showInputDialog("Enter Hourly Rate: "); rate[EmpCount] = Double.parseDouble(input); input = JOptionPane.showInputDialog("Enter Hours Worked: "); hours[EmpCount] = Double.parseDouble(input); }//end addStudent //---------------------------------------------------------------- public static void dispEmployee(int current) { JOptionPane.showMessageDialog(null, "Student SSN: " + ssn[current] + " " + "Student Hourly Rate: " + rate[current] + " " + "Student Hours Worked: " + hours[current] + " " + "Student Gross Pay: " + grossPay[current]); }//end dispEmployee //--------------------------------------------------------------- public static int searchEmployee() { for(int i = 0; i < EmpCount; i++) { if (searchSSN.equals(ssn[i])) return i; }//end for return -1; }//end searchEmployee //---------------------------------------------------------------- public static double calcGross() { double hours = 0.0; double rate = 0.0;
if (hours <= 40) { gross = (hours * rate); } else gross = (rate * 40) * ((hours - 40) * 1.5); return gross; } }//end class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started