public class ArrayTwoDimensionall {
public static void main(String[] args) {
int [][] hour = {{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}};
String [][] week = {{"Sun"},{"Mon"},{"Tue"},{"Wed"},
{"Thu"},{"Fri"},{"Sat"}};
System.out.print(" ");
for(int i=0;i<week.length;i++)
{
for(int j=0;j<week[i].length;j++)
{
System.out.print(week[i][j]+" ");
}
}
System.out.println();
displayAllArrayElements(hour);
int []total = calculateEmployeeHours(hour);
for(int i =0;i<total.length;i++){
System.out.println("The total of working hours employee "+(i+1)+" is "+ total[i]);
}
System.out.println();
int []payment = calculateMonthlyPayment(total);
for(int i=0;i<total.length;i++){
System.out.println("The monthly payment of employee "+(i+1)+" is RM "+ payment[i]);
}
double []average = calculateAverage(hour);
for (int i=0;i<average.length;i++)
{
for (int j=0;j<week[i].length;j++)
{
System.out.println("The average working hours for "+week[i][j]+" is "+average[i]);
}
}
}
public static void displayAllArrayElements(int [][]hour){
for(int i= 0;i<hour.length;i++)
{
System.out.print("Employee "+(i+1)+"|"+" ");
for(int j=0;j<hour[i].length;j++)
{
System.out.print(hour[i][j]+" ");
}
System.out.println();
}
System.out.println();
}
public static int [] calculateEmployeeHours(int[][]hour){
int[]total = new int[5];
for(int i=0;i<hour.length;i++)
{
total[i] = 0;
for(int j=0;j<hour[i].length;j++)
{
total[i] += hour[i][j];
}
}
return total;
}
public static int [] calculateMonthlyPayment(int[]total){
int []payment = new int [5];
for (int i=0;i<total.length;i++)
{
payment[i] = 0;
for(int j=0;j<total.length;j++)
{
payment[i] = ( total[i] * 50 * 4 );
}
}
return payment;
}
[B]public static double []calculateAverage(int [][]hour){
double []average = new double[7];
for(int i=0;i<hour.length+2;i++)
{
int sum = 0;
for(int j=0;j<hour.length;j++)
{
sum += hour[j][i];
average[i] = (double)(sum) / 5;
}
return average;
}[/B]
}
}