Results 1 to 5 of 5
- 10-13-2011, 10:54 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 18
- Rep Power
- 0
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:
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.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; } }
Thank you in advance/ T.S
- 10-13-2011, 11:37 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: Iteration - "dangling modifier", wrong syntax
What is the exact exception? Please copy and paste it in full.
- 10-13-2011, 11:48 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 18
- Rep Power
- 0
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?
- 10-14-2011, 12:00 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: Iteration - "dangling modifier", wrong syntax
the Membership class needs to have a contains method.
- 10-14-2011, 12:08 AM #5
Member
- Join Date
- Oct 2011
- Posts
- 18
- Rep Power
- 0
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
-
regex "iteration"
By Claymz in forum New To JavaReplies: 2Last Post: 05-11-2011, 11:39 AM -
jsp "Valu incrementing Syntax""
By nHulk in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 04-27-2011, 11:52 AM -
Syntax error in eclipse for "enum" defination.
By gunwantw in forum EclipseReplies: 1Last Post: 07-08-2010, 09:21 AM -
"Static" modifier needed?
By zerkz in forum New To JavaReplies: 8Last Post: 09-23-2009, 03:57 AM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks