I'm having an isse with a code that computes the number of hours worked for a set of hourly employees, I can't get the information to line up.
I have the basic information of the code, as shown here:
public static void main(String[] args) {
double[][] employeeHours = {
{0.0, 8.0, 8.0, 8.5, 8.0, 9.0, 0.0},
{0.0, 9.0, 9.0, 8.5, 8.0, 7.5, 0.0},
{0.0, 8.5, 8.0, 8.6, 8.6, 9.5, 2.0},
{0.0, 4.75, 6.0, 6.25, 6.5, 0.0, 0.0},
{0.0, 0.0, 0.0, 0.0, 5.25, 5.25, 6.0}};
double[] totalHoursPerEmployee = sumEmployeeHours(employeeHours);
for (double j : totalHoursPerEmployee) {
System.out.println(" worked hours " + j);
}
System.out.println(" worked");
}
public static double[] sumEmployeeHours(double[][] hours) {
double[] totalHoursPerEmployee = new double[hours.length];
for (double i = 0; i < hours.length; i++) {
int sum = 0;
for (double j = 0; j < hours[(int) i].length; j++) {
sum += hours[(int) i][(int) j];
}
totalHoursPerEmployee[(int) i] = sum;
}
return totalHoursPerEmployee;
}
static void end(String[] xnames) {
String[] names = {"Tara Teamlead", "Harry Hacker",
"Carl Coder", "Paula Programmer", "Darrin Debugger"};
for (String name : names) {
System.out.println(name);
}
}
But I can't get the final information to stay that way:
Tara Teamlead worked 41.50
Harry Hacker worked 42.00
Carl Coder worked 45.20
Paula Programmer worked 23.50
Darrin Debugger worked 16.50