Here my output is:
Employee0: 41 hours
Employee1: 37 hours
Employee2: 34 hours
Employee3: 32 hours
Employee4: 31 hours
Employee5: 28 hours
Employee6: 28 hours
Employee7: 20 hours
But I need to store my employee information in an array and get this output:
Employee7: 41 hours
Employee6: 37 hours
Employee0: 34 hours
Employee4: 32 hours
Employee3: 31 hours
Employee5: 28 hours
Employee1: 28 hours
Employee2: 20 hours
Here is my code as of now with the top output. I cant seem for see how to store the employee information in an array and print the second output.
/**Main Method**/
public static void main(String[] args)
{
/**Employee's weekly hours**/
int[][] hours = {{2,4,3,4,5,8,8},
{7,3,4,3,3,4,4},
{3,3,4,3,3,2,2},
{9,3,4,7,3,4,1},
{3,5,4,3,6,3,8},
{3,4,4,6,3,4,4},
{3,7,4,8,3,8,4},
{6,3,5,9,2,7,9}};
int[] total = calculateTotal(hours);
display(selectionSort(total));
}
/**Total Hours**/
public static int[] calculateTotal(int[][] array)
{
int [] totalHours = new int[8];
for (int i = 0; i < 8; i++)
{
int sum = 0;
for (int j = 0; j < 7; j++)
{
sum += array[i][j];
totalHours[i] = sum;
}
}
return totalHours;
}
/**Selection Sort**/
public static int[] selectionSort(int[] list)
{
for (int i = 0; i < list.length-1; i++)
{
int currentMax = list[i];
int currentMaxIndex = i;
for (int j = i + 1; j < list.length; j++)
{
if (currentMax < list[j])
{
currentMax = list[j];
currentMaxIndex = j;
}
}
if (currentMaxIndex != i)
{
list[currentMaxIndex] = list[i];
list[i] = currentMax;
}
}
return list;
}
/**Display**/
public static void display(int[] list)
{
for (int i = 0; i < list.length; i++)
System.out.print("Employee" + i + ": " + list[i] + " hours \n");
}
}