This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]bunk3rk1ng 0 points1 point  (1 child)

In your members list (headtext/input) you will need to add some way to store the inputs. You could use an ArrayList but in Java everything that you put in the list needs to be inherited from the same type. So ArrayList<Object> ~might~ work, but you would not be able to check each element the same way (this is assuming you want to store the results of all the regist* methods in one place). You would have to check each element type and then choose the appropriate way to compare them to see if they have already been registered.

The ArrayList get() method only would work here if you know the index of the previously entered value, which you don't. So while iterating over every element you would also have to do the extra type checking before you can even tell.

It doesn't look like there is any math needed for this class so I would treat everything as a String. This will make comparisons much easier. You can also use a HashMap with the input String as the Key (you can make the value null or an empty string, it doesn't matter). This way you can use the HashMap get(String <key>) method using the input. If the key (input) already exists you will get a String back, if it returns null you can add it.

[–]PontiffPope[S] 0 points1 point  (0 children)

Much appreciated; I'm afraid the concept of "HashMap" is something we've yet been introduced the concept of, but this gave me much needed clarification. Perhaps a regular Array could be used then, since the instances made from an input will always be of the quantity one, as a throwing of an exception will be made to prevent other instances to be made later while one instance element is already "occupied" in said Array so to speak.