Disclaimer I'm new to Java still learning. I have created a class called CharacterProfiles as part of my textgame to store information about a certain characters. I have created two characters so far (skeleton and zombie) and am trying to put them into an array list so that a random generator can pick either skeleton or zombie everytime the game runs. I'm having trouble getting the computer to pick one of the two characters from inside the Arraylist and print it.
My code so far.
public static void levelOne {
CharacterProfiles skeleton = new CharacterProfiles("Sword", 50, 100, 2, 100);
CharacterProfiles zombie = new CharacterProfiles("Sword", 100, 100, 2, 120);
List<CharacterProfiles> enemies = new ArrayList<>();
enemies.add(skeleton);
enemies.add(zombie);
String randomEnemyGenerator = enemies.get(new Random().nextInt(enemies.size()));
System.out.println(randomEnemyGenerator);
}
The: String randomEnemyGenerator = enemies.get(new Random().nextInt(enemies.size())); I have just gotten from trying to look up solutions on stackOverflow (I tried some other ones I found as well) but nothing seems to work. The error code I get is: Incompatible types Required java.lang.String found Characterprofiles.
Any solutions would be appreciated, thanks!