1

Ok, so this program allows user to input five adjectives and nouns, which outputs in a paragraph. There is a certain name for this game, usually found in kid's magazines..but the name escapes me right now. Ex. "Mary hopped on the (adjective) horse. and flew over the ___(noun).

I've created a class for both noun and adjectives.

class noun {
    String noun;

    noun (String _noun) {
       noun = _noun;
    }
}

class adjective {
    String adjective;

    adjective (String _adjective) {
       adjective = _adjective;
    }
}

ArrayList <adjective> small = new ArrayList <adjective>(5);
ArrayList <noun> office = new ArrayList <noun>(5);

There is some code here between above and below which adds information from textFields into array. Below, is the code that lists nouns and adjectives. Though as of now I'm only working with nouns, and will be incorporating the adjectives into paragraph later.

So I have this.

for (int x=0; x<=noun.length() - 1; x++) { //length is underlined
    temp = temp + "paragraph" + noun.get(x).noun + "more paragraph"; //get underlined        
}
paraTArea.setText(temp);

Now this has worked before when I was using integers (only I used "size()-1" instead of length) so I'm not sure if the code is freaking because I'm using strings and a class now.

Possible important note: When I did noun "dot" it wanted me to put 'class' after the dot. So I'm a little lost now.

And I just realized it will list all nouns in the place I assigned the nouns in the paragraph...but I'll figure that out later.

Anyways ideas/suggestions would be helpful! =)

5
  • 4
    Start by renaming your noun class to Noun, to avoid confusion. See the Java Naming Conventions.
    – Keppil
    May 30, 2013 at 19:22
  • What is the exact problem right now? Does it compile? Does it run? Do you get any results? Please explain.
    – PM 77-1
    May 30, 2013 at 19:23
  • 1
    Dont use same name for noun array and property of noun class. it will be confusing, also i think it may give you errors
    – smttsp
    May 30, 2013 at 19:23
  • How you declared a noun class, as array or a List ?
    – Azad
    May 30, 2013 at 19:23
  • You have to use .size() instead of length. May 30, 2013 at 19:24

1 Answer 1

1

If you want to get the noun elements which are in the office, you have to call office to write them.

 for (int x=0; x < office.length(); x++) {            //this is same as what you do
    temp = temp + " paragraph " + office.get(x).noun; 
 }
1
  • Thanks this is great! However, what should I do if length is still underlined red? And sorry this response is 3 days late, there was a serious problem with my internet connection. Jun 3, 2013 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.