Janeice DelVecchio wrote:
Campbell Ritchie wrote:This looks vaguely familiar; I could have sworn I told somebody to create an Employee object which incorporates the hours worked array.
That's a GREAT idea! I need to start thinking more OO.
Allen Hsia wrote:Am i on the right track so far?
import java.util.*;
public class Exercise623{
public static void main(String[] args) {
int[] Employee0 = {2, 4, 3, 4, 5, 8, 8};
int[] Employee1 = {7, 3, 4, 3, 3, 4, 4};
int[] Employee2 = {3, 3, 4, 3, 3, 2, 2};
int[] Employee3 = {9, 3, 4, 7, 3, 4, 1};
int[] Employee4 = {3, 5, 4, 3, 6, 3, 8};
int[] Employee5 = {3, 4, 4, 6, 3, 4, 4};
int[] Employee6 = {3, 7, 4, 8, 3, 8, 4};
int[] Employee7 = {6, 3, 5, 9, 2, 7, 9};
int SumOfHours0 = AddingHours(Employee0);
int SumOfHours1 = AddingHours(Employee1);
int SumOfHours2 = AddingHours(Employee2);
int SumOfHours3 = AddingHours(Employee3);
int SumOfHours4 = AddingHours(Employee4);
int SumOfHours5 = AddingHours(Employee5);
int SumOfHours6 = AddingHours(Employee6);
int SumOfHours7 = AddingHours(Employee7);
int[] UnsortedHours = {SumOfHours0, SumOfHours1, SumOfHours2, SumOfHours3, SumOfHours4, SumOfHours5, SumOfHours6, SumOfHours7};
for (int i = 0; i < UnsortedHours.length; i++) {
System.out.print(UnsortedHours[i] + " ");
}
}
public static int AddingHours(int[] array){
int total = 0;
for (int i = 0; i < array.length; i++) {
total += array[i];
}
return total;
}
}
import java.util.*;
public class Exercise623{
public static void main(String[] args) {
int[] Employee0 = {2, 4, 3, 4, 5, 8, 8};
int[] Employee1 = {7, 3, 4, 3, 3, 4, 4};
int[] Employee2 = {3, 3, 4, 3, 3, 2, 2};
int[] Employee3 = {9, 3, 4, 7, 3, 4, 1};
int[] Employee4 = {3, 5, 4, 3, 6, 3, 8};
int[] Employee5 = {3, 4, 4, 6, 3, 4, 4};
int[] Employee6 = {3, 7, 4, 8, 3, 8, 4};
int[] Employee7 = {6, 3, 5, 9, 2, 7, 9};
int SumOfHours0 = AddingHours(Employee0);
int SumOfHours1 = AddingHours(Employee1);
int SumOfHours2 = AddingHours(Employee2);
int SumOfHours3 = AddingHours(Employee3);
int SumOfHours4 = AddingHours(Employee4);
int SumOfHours5 = AddingHours(Employee5);
int SumOfHours6 = AddingHours(Employee6);
int SumOfHours7 = AddingHours(Employee7);
int[] UnsortedHours = {SumOfHours0, SumOfHours1, SumOfHours2, SumOfHours3, SumOfHours4, SumOfHours5, SumOfHours6, SumOfHours7};
for (int i = 0; i < UnsortedHours.length; i++) {
System.out.print(UnsortedHours[i] + " ");
}
}
public static int AddingHours(int[] array){
int total = 0;
for (int i = 0; i < array.length; i++) {
total += array[i];
}
return total;
}
}