Week 2 Exercise 39: No line break / ComparisonFailure

1,115 views
Skip to first unread message

Scott MacDonald

unread,
Jan 25, 2016, 10:57:06 AM1/25/16
to mooc.fi
Hi,

I'm having problems with week exercise 39.

So here's my deal.  I worked through all the parts of Exercise 39 piece by piece, printing the line of stars, the square, etc.  After I finished each part, I ran it with all the previous parts and it looked like the example.

When I finished all parts, they looked good, so I hit the Run Test Locally button and.... 70%

Great Sadness!  I didn't print a line break in printStars.  Well, that makes a little sense, I suppose.  I didn't want to break the line after each iteration of the loop, so I added it just outside the loop and, confident, ran the test again.

50%! Greater Sadness!  Comparison Failure.  Now my output doesn't look right either.

I'm not sure I am reading the error properly.  Can someone explain it in plain language and have a peek at my code for my issue?

Thanks!


Let me know if I linked it to the wrong place.

Thanks again,

Scott

Jarmo Isotalo

unread,
Jan 25, 2016, 11:17:23 AM1/25/16
to Scott MacDonald, mooc.fi
Hey,

Try indenting the code -- now it's highly unclear what is in the while and what is not. 
The printStars should print a bunch of stars followed by a newline. Now it prints star,newline,star,newline and so on.

Did you try running the exercise manually? (the green arrow in netbeans)

--
http://mooc.fi
---
You received this message because you are subscribed to the Google Groups "mooc.fi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to moocfi+un...@googlegroups.com.
To post to this group, send email to moo...@googlegroups.com.
Visit this group at https://groups.google.com/group/moocfi.
To view this discussion on the web visit https://groups.google.com/d/msgid/moocfi/866dc506-63ef-432f-9a84-c6ac1aa21777%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Scott MacDonald

unread,
Jan 25, 2016, 11:28:28 AM1/25/16
to mooc.fi, wolfby...@gmail.com
Hey Jamo, 

Yeah, I had been playing around with it and the new line ended up inside the look by mistake.  

Here's how I actually meant to have it: https://tmc.mooc.fi/mooc/paste/MxfNvypdp2uKNiBzT5Ap5g

So when I run them manually with the Green Arrow, I get what I expect which is the proper number of *s then the line break, but there seems to be an empty line between each line of *s.  It's not really clear whether that's in the example or not.

Hope that helps, and thanks for your input!

Scott MacDonald

unread,
Jan 26, 2016, 7:05:52 AM1/26/16
to mooc.fi
Thinking about this again this morning, and I'm looking more closely at the error message.  It says, ComparisonFailure: Problem in printSquare(3). expected:<***
[***]
***> but was:<***
***
 ]
***>

Now that seems like it's saying that it's this: [(the start of a line)***](the end of the line)
But what it's seeing is this: [(the start of a line)(\n)***(\n)](the end of the line)
My output when running the test is this:
run:
***

---
You can see there is no break before the stars, a break after the stars then the new line before the dashes that comes from the call at the bottom.

Still confused, heh.

Jarmo Isotalo

unread,
Jan 26, 2016, 7:14:36 AM1/26/16
to Scott MacDonald, mooc.fi
It seems that e.g. printSquare prints a space " " followed by newline instead of just printing an new line. 

--
http://mooc.fi
---
You received this message because you are subscribed to the Google Groups "mooc.fi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to moocfi+un...@googlegroups.com.
To post to this group, send email to moo...@googlegroups.com.
Visit this group at https://groups.google.com/group/moocfi.

Scott MacDonald

unread,
Jan 26, 2016, 8:16:20 AM1/26/16
to mooc.fi, wolfby...@gmail.com
I replaced all my System.out.println(" "); with just a standard System.out.println(); to no avail...  I don't want to look at someone else's code to get past it, but I also don't want to miss out on an essential skill when trying to move forward...

Jarmo Isotalo

unread,
Jan 26, 2016, 8:31:45 AM1/26/16
to Scott MacDonald, mooc.fi
So how does your code look at the moment, please share a new tmc-paste link

--
http://mooc.fi
---
You received this message because you are subscribed to the Google Groups "mooc.fi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to moocfi+un...@googlegroups.com.
To post to this group, send email to moo...@googlegroups.com.
Visit this group at https://groups.google.com/group/moocfi.

Scott MacDonald

unread,
Jan 26, 2016, 8:57:55 AM1/26/16
to mooc.fi, wolfby...@gmail.com

Jarmo Isotalo

unread,
Jan 26, 2016, 9:12:46 AM1/26/16
to Scott MacDonald, mooc.fi
Ok, so in the printStars I feel you are making it more complicated than necessary. 
The System.out.println(); should be outside of the while loop and without the if statement.

Also there are some incorrect indentations which makes the code harder to read.


--
http://mooc.fi
---
You received this message because you are subscribed to the Google Groups "mooc.fi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to moocfi+un...@googlegroups.com.
To post to this group, send email to moo...@googlegroups.com.
Visit this group at https://groups.google.com/group/moocfi.

Scott MacDonald

unread,
Jan 26, 2016, 9:40:08 AM1/26/16
to mooc.fi, wolfby...@gmail.com
Try this: https://tmc.mooc.fi/mooc/paste/Yfx3MgoXKIE1040RSFR3lg

I added the if just to make 100% sure it didn't run the println until the end as well, but I know it mucked it up.
Removed the IF, put the println where it should be and did some indent work.

Jarmo Isotalo

unread,
Jan 26, 2016, 10:54:55 AM1/26/16
to Scott MacDonald, mooc.fi
Ok, 
So the next one, the printSquare now prints for input of 3:
***

***

***

instead of printing
***
***
***
So for each "line of stars" there is two times newline added.
One by the printStars (which really seems to be working properly) and second from the method printSquare.

--
http://mooc.fi
---
You received this message because you are subscribed to the Google Groups "mooc.fi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to moocfi+un...@googlegroups.com.
To post to this group, send email to moo...@googlegroups.com.
Visit this group at https://groups.google.com/group/moocfi.

Scott MacDonald

unread,
Jan 26, 2016, 10:59:00 AM1/26/16
to mooc.fi, wolfby...@gmail.com
Have you every considered the Criminal Mastermind career path?  I actually added those line breaks at some point late in the game and didn't think of them.  You're a genius!  If I had been better able to read the error message I'd have figured it out, maybe, heh.

Thanks again!

Jarmo Isotalo

unread,
Jan 26, 2016, 11:00:48 AM1/26/16
to Scott MacDonald, mooc.fi
The error messages are somewhat confusing as in the error message there is no distinction between newline and whitespace...

Reply all
Reply to author
Forward
0 new messages