Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link

Ryan Mcguin

Greenhorn
+ Follow
since Dec 17, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ryan Mcguin

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);
}
}
13 years ago
Also, I have gotten here so far but my printout is my big problem yet again... hmmm?

[edit]Add code tags and delete unnecessary newlines. CR[/edit]
[ December 17, 2008: Message edited by: Campbell Ritchie ]
13 years ago
I, again, need to print the employees, their hours and have it sorted in descending order of total hours... i have this so far now...


[edit]Add code tags. CR[/edit]
[ December 17, 2008: Message edited by: Campbell Ritchie ]
13 years ago
hey i'm new to programming and I was clicking around. I started playing with this program and to print it out i am getting confused.. this is what i have so far.. if anyone can help that'd be awesome! and i'm trying to give it a box look with day of the week and the employee 1-8 on the side like this

SunMonTueWedThurFri Sat Total
Employee 1243458834

Employee 2734334428

Employee 3334332220

Employee 4934734131

Employee 5354363832

Employee 6344634428

Employee 7374838437

Employee 8635927941





public class Proj4
{ /** Main method */
/** Main method */
public static void main(String args[]) {

//creating 2-dimensional array for employee's 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[] sum1 = sumIt(hours);



}


public static int[] sumIt(int[][] numbers){

int sum[] = new int[8];

for (int i = 0; i < numbers.length; i++){
int total = 0;
for (int j = 0; j < numbers[0].length; j++)
total += numbers[i][j];

sum[i] = total;
}
public static void Printit(int employee[][])
{
String days="Emp Sun Mon Tue Wed Thur Fri Sat Total Hours";
int row=0,col=0;
String spaces=" ";
String spaces2=" ";

System.out.println(days);
System.out.println("==============================================");
for(row=0;row<=7;++row)
{
System.out.print(spaces);
for(col=0;col<=8;++col)
{
System.out.print(employee[row][col]+spaces2);
}
System.out.println();
}
}
}
13 years ago