/*filename:P6Q22.java
*Name:Wang Chaoran
*Description:
(Computing the weekly hours for each employee) Suppose the weekly hours for all employees are
stored in a two-dimensional array. Each row records an employee's seven-day work hours with
seven columns. For example, the following array stores the work hours for eight employees.
Write a program that displays employees and their total hours in decreasing order of the total hours.
*/
class P6Q22{
public static void main(String[] args){
int[][] test={{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 sum = 0;
int[] hour=new int[test.length];
int[] trace=new int[test.length];
for(int i=0;i<test.length;i++){
for(int j=0;j<test[i].length;j++)
hour[i]+=test[i][j];
trace[i]=i;
}
sort(hour,trace);
print(hour,trace);
}
static void sort(int[] hour,int[] trace){
for(int i=0;i<hour.length;i++){
int current = hour[i];
int current1= trace[i];
int j;
for(j=i-1;j>=0&&hour[j]<current;j--){
trace[j+1]=trace[j];
hour[j+1]=hour[j];
}
trace[j+1]=current1;
hour[j+1]=current;
}
}
static void print(int[] hour,int[] trace){
for(int i=0;i<hour.length;i++){
System.out.println("Employee"+trace[i]+" "+hour[i]+" hours");
}
}
}