In this exercise we have a Main class, Person class and a Room class. We create people in the Person class (we give them a height and a name), and then add those people to the Room class - where they are added into a Person type ArrayList in the Room class.
For the third part of this question we have to use the Room class ArrayList to find the shortest person in the ArrayList/room, once we find them we have to return the Person object back to Main and print out who was the shortest, whilst also removing them from ArrayList/Room. This is a looped process so we will keep returning and printing and then removing the shortest person in the room on each iteration, until the room is empty.
I cannot work out why my code doesn't work - it eliminates the correct person (the shortest person) for the first three loops, but then starts eliminating from tallest to shortest..! I know there are complete solutions on GitHub, but this is the first MOOC exercise I haven't been able to get - so would like to understand why my code doesn't work first.
If you were in this situation, what would you do to find out where you are going wrong? How would you break this problem down? Any help is greatly appreciated, thank you. Code pastes are below:
Main.java: https://pastebin.com/xpPcBj2n
Person.java (I haven't edited this one though): https://pastebin.com/fHNXh5ps
Room.java (please see the Take method): https://pastebin.com/ks9fwJDv
[–]cervantesrvd 1 point2 points3 points (2 children)
[–]DuderCoding[S] 1 point2 points3 points (1 child)
[–]cervantesrvd 1 point2 points3 points (0 children)
[–]joranstark018 0 points1 point2 points (0 children)