I'm new here, so I'm not sure if it's ok to have 2 questions in the same post, so if I'm not supposed to just tell me (nicely!) and I'll change it to one question here and start another post elsewhere.
First problem:
Below on lines 5-8 I'm referring to two strings that I need to compare to see if they are the same. I'm using the getUserInput()
method to get a response from the user at terminal and then I'm having it go ahead and print both strings so that I can visually inspect them, and they are coming up the same. However, the if
section that is supposed to run when they are the same never runs and then the else
section always does.
Second problem:
In the else
section right below, whenever the currentChump
's health is reduced to < 1
, I get a block of exceptions that I've never seen before and don't know what do do about.
Here is my code, and then below I will paste the exception:
for (Chump currentChump : chumpArray) {
System.out.println(" ");
String playerChoice = helper.getUserInput(
"Type the name of the Weapon that you wish to use.");
System.out.println(playerChoice);
System.out.println(currentChump.getWeakness().toLowerCase());
if (currentChump.getWeakness().toLowerCase() == playerChoice) {
chumpArray.remove(currentChump);
} // END IF
else {
while (PlayerIsAlive && currentChump.getHealth() > 0) {
int damage = (int) Math.floor((Math.random() * 6) + 1);
System.out.println(currentChump.getName() + " has "
+ currentChump.getHealth() + "health remaining.");
currentChump.setHealth(currentChump.getHealth() - damage);
System.out.println("You hit the enemy for "
+ damage + " points of damage.");
System.out.println(currentChump.getName() + " has "
+ currentChump.getHealth() + " health remaining.");
System.out.println(" ");
if (currentChump.getHealth() < 1) {
chumpArray.remove(currentChump);
} // END IF
else {
int damage2 = (int) Math.floor((Math.random() * 4) + 1);
player.setHealth(player.getHealth() - damage2);
if (player.getHealth() < 1) {
PlayerIsAlive = false;
} // END IF
} // END WHILE
} // END ELSE
} // END ELSE
} // END FOR
exception:
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at ArenaGameCopy.startPlaying(ArenaGameCopy.java:87)
at ArenaGameCopy.main(ArenaGameCopy.java:168)