Question
a) Ask the user for the number of employees
b) For each employee:
a. Collect each employee name (store in String[] empNames)
b. Collect the Pay Rate for Each employee
c. Collect the hours for each employee in a 2D array (use double[][] hours)
c) Calculate the total hours for each employee (use double[] empHours)
For this part, you must reference the dimensions of the ‘hours’ array in controlling the loops.
d) Calculate the total hours for each day (use double[] dayHours)
e) Calculate how much they should be paid for the hours they worked
f) Report the results in a formatted table using printf.
Recall that %s is used for Strings, %f for doubles.
%-10s will left align a String in a column of width 10
%10.4f will show double values with 4 digits to the right of the decimal point in a column of width 10
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
import java.util.Scanner;public class HoursReportingProgram {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int num;
Scanner keyboard = new Scanner(System.in);
//a) Ask the user for the number of employees
System.out.print("How many employees: ");
num = keyboard.nextInt();
if (num > 0) {
String[] empNames = new String[num];
double [] payRate = new double[num];
double[][] hours = new double[num][7];
double[] empHours = new double[num];
double[] dayHours = new double[7];
double [] income = new double[num];...