So im working on some homework and I can't figure out how to make an String array[a] pass into a method in another class and be recorded as a String array there. This is kinda hard to explain since its new to me, but here is what I'm trying to do.
Tester Program:
Purse c = new Purse();
c.addCoin("Quarter");
c.addCoin("Penny");
c.addCoin("Nickel");
c.addCoin("Dime");
Purse d = new Purse();
d.addCoin("Nickel");
d.addCoin("Dime");
d.addCoin("Dime");
d.addCoin("Quarter");
System.out.println(c.sameCoins(d));
System.out.println("Expected: false");
Purse class:
public boolean sameCoins(Purse other)
{
if (array1.length != array2.length)
{
return false;
}
int same = 0;
for (int i = 0; i < array1.length; i++)
{
for (int x = 0; x < array2.length; x++)
{
if (array2[x].equals(array1[i]))
{
same++;
break;
}
}
}
return same==array1.length;
}
I know array1 and array2 aren't proper variable/names for the arrays but that just to substitute the idea I'm trying to get at.