10 male and 10 female fishes are added to an infinite pond. Fishes randomly meet other fish in the pond according to the rules.
- If two male fishes meet they kill each other
- If two female fishes meet one of them dies at random
- If male and female fish meet they spawn two new fishes of random gender
- Fishes which are in meeting cannot be used by other threads
Simulate the infinite pond using 5 threads. Print the number of fishes remaining after each meeting. If all the fishes are dead, terminate the program.
Hint : Use Arraylist and java.util.Random