Bookmark Topic Watch Topic
  • New Topic

double array file cleared up  RSS feed

 
Ryan Mcguin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator
Here is my final effort in trying to make that table work...



public class WeeklyHours {
public static void main(String[] args) {
int [][]employee_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 = new int[8];
int[] employee_number = new int[8];
int[] col_total = new int[7];
for (int b = 0; b <= 7; b++)
{
employee_number[b] = b+1;
}

getTotal(total, employee_hours,col_total);

SortLow(employee_hours, total,employee_number);

Printit(employee_hours, total, employee_number,col_total);
}
public static void getTotal(int[] total, int[][] employee_hours,int[]col_total)
{
//int x = 0;
for (int i = 0; i <= 7; i++)
{
for(int y = 0; y <= 6; y++)
{
total[i] = total[i] + employee_hours[i][y];
col_total[y]=col_total[y]+employee_hours[i][y];
}
}
}
public static void SortLow(int[][] employee_hours, int[] total,int []employee_number)
{
int[] tempArray;
int temp;

for (int c = total.length -1; c >= 1; c--)
{
int Current_Max = total[0];
//int currentMax = employee_hours[0];
int Current_Max_Index = 0;
for(int d = 1; d <= c; d++)
{

if (Current_Max < total[d])
{
Current_Max = total[d];
//currentMax = employee_hours[d];
Current_Max_Index = d;
}
}
if (Current_Max_Index != c)
{
total[Current_Max_Index] = total[c];
total[c] = Current_Max;

tempArray = employee_hours [Current_Max_Index];
employee_hours[Current_Max_Index] = employee_hours[c];
employee_hours[c] = tempArray;

temp=employee_number[Current_Max_Index];
employee_number[Current_Max_Index]=employee_number[c];
employee_number[c] = temp;
}
}
}
public static void Printit(int[][]employee_hours, int[] total,
int[] employee_number,int [] col_total)
{
String days=" Emp Mo Tue Wed Thu Fri Sat Sun Total";
int row=0,col=0;
String spaces=" ";
String spaces2=" ";

System.out.println(days);
System.out.println("======================================================================");
for(row=0;row<8;++row)
{

System.out.print("Employee: "+employee_number[row] + spaces);
for(col=0;col<7;++col)
{
System.out.print(employee_hours[row][col]+spaces2);
}
System.out.println(total[row]);
}
System.out.print("TOTAL ");
int grandtotal=0;
for(col=0;col<7;++col)
{
System.out.print(col_total[col]+" ");
grandtotal=grandtotal+col_total[col];
}
System.out.println(grandtotal);
}
}
 
Eric Daly
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Report post to moderator
...
I'd like to know what problem you're having so I could try to help you.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please repeat that post on your existing thread. I am afraid I shall have to close this thread as a duplicate.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!