This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Cattle Drive and the fly likes Math class permissible in Say 4b? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Math class permissible in Say 4b?" Watch "Math class permissible in Say 4b?" New topic
Author

Math class permissible in Say 4b?

Joe McGuire
Ranch Hand

Joined: Mar 19, 2001
Posts: 293
I've just completed my discouraging fifth attempt at Say 4b. Each time I look at it I see different ways of doing things, and I'm not sure which are preferred (or permissible).
I'm getting a little worried too, because if I use a method in the Math class, my code is cut down to 2 methods, 106 lines (10 blank lines, 7 comment lines, 89 lines of code).
Is the use of the Math class permissible, and am I going to get hammered for having only two methods?
Panday Manako
Ranch Hand

Joined: Mar 29, 2001
Posts: 80
i once used the math class. i also have only 2 methods. Marilyn will just tell you to use the good old divide and mod. she's right. i ended up with almost the same length of codes even shorter.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
Oh Joe, Sayb took me 9 tries and a lot of sleep deprivation. Methods are a complicated concept for me, but if you DON'T GET DISCOURAGED and KEEP HAMMERING AWAY AT IT you WILL get there. One little step at a time. Take plenty of water. There will probably be vultures...... I saw some.
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
Joe I'm not sure if you'l get hammered.
The "golden rule" for Say 4b is "use 4a as you base".
Look at the instrutors for 4a carefully and implement it in you solution for 4b.
Adam Vinueza
Ranch Hand

Joined: Apr 16, 2001
Posts: 76
I tried the Math class too, after I saw a pattern emerge in all the triples of zeroes. I found two problems. First, it didn't save me all that much code. Second, the formula I ended up using was so complex that it would just make work for me to explain it to the next poor cowpoke who reads my program, and given that it didn't save that much code, it seemed better to just go with the divide/remainder method.
And if I recall what 4b says about the instructor's solution, it's only 88 lines of code, so there must be some way to do the thing reasonably efficiently without resorting to the Math class. Although as I'm still on 4a, I wouldn't know what way that is yet.
Incidentally, I'm still awed by Carol's mental endurance. I've decided to model part of my new psyche on hers.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
Mental endurance? Everyone else just calls me stubborn!!!
Adam Vinueza
Ranch Hand

Joined: Apr 16, 2001
Posts: 76
I should be so stubborn!
Joe McGuire
Ranch Hand

Joined: Mar 19, 2001
Posts: 293
It is quite a complicated statement, but it replaces an entire method. I'll see if I can find another way without using it, perhaps with the mod/divide.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
Mod & divide are part of the key to 4b! You're getting warmer......
Michael Pearson
Ranch Hand

Joined: Mar 11, 2001
Posts: 351
In my opinion, this is the most interesting assignment of the first 8.
Although there are many ways to code Say(B) the instructor�s solution is quite good. I wrote solutions that used more lines of code and I wrote some that took fewer lines of code. Keep it simple and it will turn out elegant.
Inside every complex program is a simple program trying to get out.
I wrote programs that used several different techniques prior to submitting my first attempt for nitpicking. My background is in procedural programming so I'm very comfortable with recursive iterations. I probably never saw a looping algorithm I didn't like. Eventually I'll learn to drop this bad habit.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Math class permissible in Say 4b?
 
Similar Threads
Say 4b question
Say 4b - completely stumped
4b Say
Java-4b technique
Say 4b just got harder...