Using charAt and other string methods in a created class
I am in the process of creating a class for trivia questions which are read from an input file. Each question has multiple choices which are being stored as elements of an ArrayList<String>. Now that this is done, I need to identify which answer is the correct one. Each choice is on a different line of the input file, and the correct choice has an asterisk character as the first character in its string. I wanted to use to charAt(0) on each element of the array list and loop through each choice until the asterisk was found, but I cannot use this method in my class since it is not defined. Does this deal with inheritance? How would I fix this?
Re: Using charAt and other string methods in a created class
Quote:
I wanted to use to charAt(0) on each element of the array list and loop through each choice until the asterisk was found, but I cannot use this method in my class since it is not defined.
I'm not sure I understand this - especially the "since it is not defined" bit.
You can put the code that determines the correct answer either in the Question class, or outside it. That really depends on how you are defining the Question class (ie what behaviour you intend it to have). Either way though every class you have will be defined!
Perhaps if you posted the code you have so far, and said where and what you are trying to do it would help.
-----
There is nothing so far that suggests that inheritance is involved.