Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By sunde887

Thread: Iteration - "dangling modifier", wrong syntax

  1. #1
    Tom_Snake is offline Member
    Join Date
    Oct 2011
    Posts
    18
    Rep Power
    0

    Default Iteration - "dangling modifier", wrong syntax

    Hi, I'm one month into my java training, and I have a small problem. I can't seem to make references to the correct object, only to the objects class.

    (I'm using bluej by the way, just so I'll really get the basics of the language.)

    Here's my fawlty code:

    Java Code:
    public int joindeInMonth(int month){
        //begin with test of int
        if(month < 1 || month > 12) {
                throw new IllegalArgumentException(
                    "Month " + month + " out of range. Must be in the range 1 ... 12");
            }
            
        //continue with iteration
        int numberJoined = 0;
        Iterator<Membership> it = members.iterator();
        while (it.hasNext()){
            Membership member = it.next();
            if(member.contains(month)){
                numberJoined++;
            }
        
    
        //end with print number of result.
            return numberJoined;
        } 
    }
    It's a simple search for this and print the result, but line nr 13 is incorrect. How am I supposed to think and write if I want the result to be how many members joined in the selected month? Members consitsts of a String and two different int.s.

    Thank you in advance/ T.S

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: Iteration - "dangling modifier", wrong syntax

    What is the exact exception? Please copy and paste it in full.

  3. #3
    Tom_Snake is offline Member
    Join Date
    Oct 2011
    Posts
    18
    Rep Power
    0

    Default Re: Iteration - "dangling modifier", wrong syntax

    If by exception you mean the line the compiler spits out after finding an error, then this would be it : cannot find symbol - method contains(int).
    Otherwise, please excuse my ignorance and please develop the meaning of "exception".

    Did you understand what I was trying to do or was my question poorly formulated?

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: Iteration - "dangling modifier", wrong syntax

    the Membership class needs to have a contains method.
    Tom_Snake likes this.

  5. #5
    Tom_Snake is offline Member
    Join Date
    Oct 2011
    Posts
    18
    Rep Power
    0

    Default Re: Iteration - "dangling modifier", wrong syntax

    Thank you for guiding me, I would have been stuck for days if not. I thought members.contains was something built in to the ArrayList class and worked in mysterious ways, but I guess it isn't. I edited the code, creating a contains method in Membership; works like a charm. Thank you once again

Similar Threads

  1. regex "iteration"
    By Claymz in forum New To Java
    Replies: 2
    Last Post: 05-11-2011, 11:39 AM
  2. jsp "Valu incrementing Syntax""
    By nHulk in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 04-27-2011, 11:52 AM
  3. Syntax error in eclipse for "enum" defination.
    By gunwantw in forum Eclipse
    Replies: 1
    Last Post: 07-08-2010, 09:21 AM
  4. "Static" modifier needed?
    By zerkz in forum New To Java
    Replies: 8
    Last Post: 09-23-2009, 03:57 AM
  5. Replies: 2
    Last Post: 01-24-2009, 06:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •