Q Tran

Greenhorn
+ Follow
since Oct 22, 2009
Merit badge: grant badges
For More
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 Q Tran

Hey there everyone, first post here so please excuse any mistakes

Ok so I have this assignment here:

Suppose the weekly hours for all employees are stored in a two dimensional array. Each row records an employee's seven-day works 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.
Su Mon Tue Wed Thu Fri Sa
Emp 0 2 4 3 4 5 8 8
Emp 1 7 3 4 3 3 4 4
Emp 2 3 3 4 3 3 2 2
Emp 3 9 3 4 7 3 4 1
Emp 4 3 5 4 3 6 3 8
Emp 5 3 4 4 6 3 4 4
Emp 6 3 7 4 8 3 8 4
Emp 7 6 3 5 9 2 7 9

The final output is supposed to look like this:

Employee 7 : 41
Employee 6 : 37
Employee 0 : 34
Employee 4 : 32
Employee 3 : 31
Employee 1 : 28
Employee 5 : 28
Employee 2 : 20

Ok... so what i have done so far is create the 2D array and then made a new loop to add across each row and store that value into a new array. that looks like this
[34 28 20 31 32 28 37 41]

And I used the reverseOrder method to sort it into descending order. I then use the binarySearch function to find out which employee had what hours... but it doesnt seem to work. Any inputs would be greatly appreciated!


Oh and my current output is this:

34
28
20
31
32
28
37
41

41
37
34
32
31
28
28
20
Employee 7 has this many hours: 41
Employee 6 has this many hours: 37
Employee -7 has this many hours: 34
Employee -7 has this many hours: 32

Employee 3 has this many hours: 31
Employee 1 has this many hours: 28
Employee 1 has this many hours: 28
Employee -1 has this many hours: 20


I dont get why the negative numbers are appearing?? and how do i get it to read employee 5 and not just stop at employee 1?
14 years ago