anybody knows some basic java?

Bacardi151

Senior member
Dec 15, 2003
540
0
0
what i'm doing is trying to build a class called Set

and i'm testing this class with another class...let's call it Test

in the class Test, i will initiate 2 arrays and have it passed to the class Set.

how do i do that?

let's say i have a method in class Set called manipulate and it is non-static

and the method will manipulate array1 and array2 and set it to array3

so it would look something like this in class Test: array3 = array1.manipulate(array2);

but what Type do i set array1, array2, and array3 to? i thought i was suppose to set them to type Set[] but it keeps giving me errors about incompatibility as i initiated array1 and array2 to a set of numbers, so it says something about "expecting int, found Set[]"

hope somebody gets what i'm saying, if not i'll be more than happy to elaborate on this

thx in advance
 

Hector13

Golden Member
Apr 4, 2000
1,694
0
0
not sure i understand what you are saying... but are array1, array2, and array3 supposed to be arrays of primitives (ie ints) or are they supposed to be instances of your Sets class?

 

Bacardi151

Senior member
Dec 15, 2003
540
0
0
"but are array1, array2, and array3 supposed to be arrays of primitives (ie ints) or are they supposed to be instances of your Sets class?"

could you explain the difference?

all i know is that (from the project instruction) is that the arrays are "referenced", so i thought they're set in class Test and then they are passed or referenced (is there a difference between passing and referencing?) to class Set.

in your opinion, what is the best way to do this

initiating the arrays in Set or Test? i'm a java newbie and this project is killing me because i actually never took the 2 java classes prior to this one (dont ask me why, i somehow just got into this third java class).

the goal in this program is to write 4 methods , i'll use one example ....which is called "union"

when i write C = A.union(B) it will take the set of objects of A ...lets say A = {1, 3, 5, 7} and B = {3, 4, 5} and it will unionize A and B, that is to say, they put both of them into C, but no duplicates, so C = {1, 3, 4, 5, 7} (note 3 and 5 were not copied over to C twice).

and from my understanding when you write A.union(B) instead of Set.union(A, B), it means that union is non-static, so the methods parameter should look like this "public method (Set A, Set B) ....or am i suppose to write public method (Set[] A, Set[] B)? i'm confused as of how to pass arrays. and how to initiate them in another class to refer to the class you're calling/invoking.

sorry if i make this more confusing but i think this is about how well i can put it for the time being
 

Hector13

Golden Member
Apr 4, 2000
1,694
0
0
My guess is that you want array1, array2, array3 to be arrays of ints. Then you probably want to make "sets" using those arrays. Or you could just skip the intermediate array variables (array1, array2, and array3) and do something like:

Set set1 = new Set([1, 3, 5, 7])

Where you have a public constructor that looks like:
public Set(int[] array)

As for your union method, if you make it non-static, the definition should look like:
public union(Set setB)

my guess is that you should never need to use an array of Sets (it looks like you set class is meant to represent an array internally)