Hi Renne Bautista,
Apart from what has been mentioned already, there are more things to pay attention on:
1. Even tho, if this class is just for a
test purpose, please keep in mind when you implement non-test, that instance variables in most cases should be private. Do differently if you have valid reason to do so.
2. Also, name variables so they'd reveal their purpose from the first glance. i.e. variables
h,
z are not descriptive and self explaining. Such things shouldn't be practiced even in test classes.
3. Don't really understand why you initialize z to -1? and in this matter using while loop which iterates in that way. Shouldn't be easier to use traditional form of
for loop and iterate from 0 till ... ?
4. Each Hobbit you name as "bilbo", and later on if it turns out that it is 1 or 2 you rename it accordingly. That is also not very correct. Think of case how to name it once.
5. On lines 10 and 13 you have two
if statements. Consider in such cases using
else if. Bear in mind, it is going to be either 1 or 2, but never both.
6. Last thing. Try do not cram everything to a
main method, as it suppose to start your application only.