I have a class called Alien and then 3 classes extending that called SnakeAlien, MarshMallowAlien, and OgreAlien...I also have a class called AlienPack which creates an Array of Alien Objects with their NAME, type of alien and health... and in my TestAlien Class i need to sort through the AlienPack and find out which Aliens are equal(type and health)
so i wrote a for loop to do this....but what I got was each Aliens name = other Aliens name TWICE, because it displays that and then the other way too like this
Aliens name = other Aliens name
other Aliens name = Aliens name
So what i need help with is...I only need one of those to appear!! here is my testAlien source and output...let me kno if you need to see any other classes .
CODE
public class TestAlien {
/**
* @param args
*/
public static void main(String[] args) {
int maxPackSize = 15;
int [] health = {50, 80, 70, 60, 70, 80, 100, 90, 80, 0, 100, 30};
String [] name = {"Tim", "Agypt", "Lee", "Jason", "Mike", "Victor", "David", "Tiffany", "Katie", "Dan", "Cody", "Leeanna"};
String [] type = {"O", "S", "M", "S", "M", "M", "O", "O", "S", "S", "O", "S"};
System.out.println("List of pack members: ");
AlienPack pack = new AlienPack(12);
for(int i=0; i <=11; i++){
if(type[i] == "O"){
Alien al = new OgreAlien(health[i], name[i]);
pack.addAlien(al);
System.out.println(al.toString());
}
else if(type[i] == "S"){
Alien al = new SnakeAlien(health[i], name[i]);
pack.addAlien(al);
System.out.println(al.toString());
}
else if(type[i] == "M"){
Alien al = new MarshmallowAlien(health[i],name[i]);
pack.addAlien(al);
System.out.println(al.toString());
}
}
System.out.println();
System.out.println("Total pack damage: " + pack.calculateDamage());
System.out.println();
System.out.println("Names of equal pack members: ");
String[] used = new String[12];
boolean isUsed = false;
int i = 0;
do{
for(int j=1; j < pack.getPackSize();j++){
for(int k=0;k < used.length;k++){
if(pack.getAlien(i).name == used[k]){
isUsed = false;
}
else
isUsed = true;
}
if(pack.getAlien(i).equals(pack.getAlien(j))){
if(pack.getAlien(i) == pack.getAlien(j)){
;
}
else{
System.out.println(pack.getAlien(i).name +" " + pack.getAlien(j).name);
}
}// end if
}// end for loop
used[i]= pack.getAlien(i).name;
i++;
}while(i < pack.getPackSize());
}//end main
}
and the output is
CODE
List of pack members:
Tim 50 Ogre
Agypt 80 Snake
Lee 70 MarshMallow
Jason 60 Snake
Mike 70 MarshMallow
Victor 80 MarshMallow
David 100 Ogre
Tiffany 90 Ogre
Katie 80 Snake
Dan 0 Snake
Cody 100 Ogre
Leeanna 30 Snake
Total pack damage: 67.4
Names of equal pack members:
Agypt Katie
Lee Mike
Mike Lee
David Cody
Katie Agypt
Cody David
Thanks