Lab03

Base project

Use project at https://gitlab.vsb.cz/jez04-vyuka/java-efrei/efrei-lab03.git as a base to complete the following tasks.

Import to Eclipse:

  • File -> Import... -> project from Git (with smart import) -> Clone URI -> (use above link as URI) -> Next -> Next -> Finish

Open in InteliJ IDEA:

  • File -> New -> Project from Version Control... -> (use above link as URL) -> Clone

Replace array with collection

Use some collection (ArrayList, LinkedList, ...) to work with monsters and heros instead of array.

Fill the collection

Generate several (random) number (big) of monsters and herose using methods in class Utils

  • Use method Utils.generateHeroName() and Utils.generateMonsterName() to generate instance of Monster or Hero
  • Use for loop to create many objects and add them into collection

Make world danger

Run several number of fights between random choosen fighters.

Go throught collection

Use foreach loop to go throught collection and calculate average streanght of fighters, monsters and heroes.

Remove from collection

Try to  remove fighters which are dead from collection

  • Try do it inside foreach loop
  • Use different collection to store object to remove fro collection with method removeAll
  • Use for loop with index to remove object base on index. Start at begining of List and on the end of List.
  • Try use Iterator to go through collection and remove fighters.

Maps

Use Map (HashMap) to calculate number of fighters with same name.

  • Create map of keys (names - Strings) and value as Integer (count of names).
  • Go throught collection and increase number of counts (value) for each name (key)
  • Print out all keys (names) and values (count)

Solution

solution can be found in project original project in branche solution