Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Using charAt and other string methods in a created class

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    1,069
    Thanks
    7
    Thanked 215 Times in 191 Posts

    Default Re: Using charAt and other string methods in a created class

    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.

Similar Threads

  1. Use of Exceptions and Methods of The String Class
    By cagataylina in forum Exceptions
    Replies: 1
    Last Post: April 26th, 2011, 02:56 AM
  2. Diff between spring created been and instance of class
    By tcstcs in forum Web Frameworks
    Replies: 0
    Last Post: April 5th, 2011, 01:54 AM
  3. Running methods of a class that created you...
    By joestr in forum Java Theory & Questions
    Replies: 2
    Last Post: April 3rd, 2011, 02:59 PM
  4. Replies: 2
    Last Post: February 28th, 2011, 10:51 AM
  5. Help requested - testing a class with a tester class, no methods allowed.
    By miketeezie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 21st, 2011, 10:40 PM

Tags for this Thread