Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

Allen Hsia

Greenhorn
+ Follow
since Oct 29, 2009
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 Allen Hsia

Ok i search and im' sure there i couldn't find something like this.

Design a class named MyInteger. The class contains:
**An int data field named value taht stores the int value represented by thsi object.
**a constructor that creates a MyInteger object for the specified int value
**A get method that returns the int value.
**Methods isEven(), isOdd(), and isPrime() that return true if the value is even, odd, or prime, repectively.
**Static methods iEven(int), isOdd(int), and isPrime(int) taht return true if the specified value is even, odd, or prime, respectively.
**Static methods isEven(MyInteger), isOdd(MyInteger), and isPrime(MyInteger) that return true if the specified value is even, odd, or prime, respectively.
**Methods equals(int) and equals(MyInteger) taht return true if the value in the object is equal to the specified value.
** a static method parseInt(char[]) that converts an array of numeric characters to an int value.

draw the UML diagram for the class. implement the class. Write a cleint program taht tests all methods in the class.

I"m at the returning Prime if the number is prime.
How do i prove it's prime? I know how to prove if it's even or odd but prime is only divisible by one and itself.

12 years ago

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.



Um we haven't learned objects yet...
12 years ago
Yay! I got it to descend!



NOw i just don't know how to put the employees in the right spot.
12 years ago


I can't really see the error in this line



After the first parenthesis i'm supposed to put the array i want to reverseOrder...
I did that. I copied the array from totalHours to sorted in order to reverse the order...

But it says cannot find symbol - method sort(int[], java.util.Comparator<java.lang.Object>)
12 years ago
Okay Should i post on the other thread since someone else already is doing the same problem i'm doing?
12 years ago


If anybody is reading this...
This is what i have so far. I'm getting tired. and on my compiler it says that


has an error called "incompatible type - found int[] but expect int." Both of them have a bracket so... i don't know what's wrong
12 years ago
I understand the general concept of coding.
Break into small pieces/jobs/tasks
12 years ago
I'm sorry for being really noobish.

I'm having a lot of stress balancing my highschool senior year homework with my 1 sememster online Java class.
I've been working all day on Java...
12 years ago
Basically we're supposed to have this as a result

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

We're supposed to sort the hours in descending order with the employees in the correct spot.

In the textbook I can only sort it in ascending order but it never mentions to sort it in descending order...
all we were given is this

java.util.Arrays.sort(totalHours); //totalHours being the array of the unsorted hours.
12 years ago


This is what i have so far...? am i getting there?
12 years ago

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;
}

}



Lol well i forgot to implement the sorting part...
But when i implement the sort, how do i put the employees next to the correct hours?
12 years ago
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;
}

}

12 years ago
Okay this is the very last question on my homework.

The others are finished with the tips and help on my last post on increasing array size...

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
Employee 0 2 4 3 4 5 8 8
Employee 1 7 3 4 3 3 4 4
Employee 2 3 3 4 3 3 2 2
Employee 3 9 3 4 7 3 4 1
Employee 4 3 5 4 3 6 3 8
Employee 5 3 4 4 6 3 4 4
Employee 6 3 7 4 8 3 8 4
Employee 7 6 3 5 9 2 7 9

I really don't know how to start this...
Should i put the hours of each employee in an array and sum it up?
And then store al the sum'd up numbers in an another array and sort it out in decreasing order?

If i manage to do that? How would i get the number like employee "5" to be at specific locations?

I'm baffled right now...

This is waht i have so far...

12 years ago
YAY IT WORKED!!!

the result i got was
1
2
0
0

the 0's are there because there aren't any values in the array right?

12 years ago