File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Cattle Drive and the fly likes 4b structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "4b structure" Watch "4b structure" New topic
Author

4b structure

Adam Price
Ranch Hand

Joined: Nov 11, 2005
Posts: 95
I am working on 4b.

Currently, my strategy is two pronged
1. I have a method that will take any three digits and name them as the units period is conventionally named. (432 = four hundred thirty two)
2. My second method breaks a multi-period number up into it's periods (billions, millions, thousands and units), then feeds any non-zero period through the first method and appends the name of the period followed by a comma if necessary.

This second method seems to me a little long winded, but crystal clear.

My nitpicker says: Notice how there's a bunch of similar code in your method? You take a number, do some calculations on it, send it to a method, print out a label, do some checking, and print out a comma.
I wonder if you could simplify your method if you went through that process only once? (You'd have to call the method more than once, of course, and pass it the parameters it would need for each case then...)


I am stumped. Every time I try to tease out a new structure, I end up either with something much more complicated, involving arrays of period names and cryptic if-tests or I end up basically gutting this second method and rewriting most of it with a new name.

Any direction?



Also - easier - My second method uses the values one million and one billion. It was suggested that I make identifiers for them instead of typing out a bunch of zeros ([int oneMillion = 1000000. Given that, since they are used only in the second method, why is it preferable to pull them out of the method and have them be static finals for the whole class?
Stuart Goss
Ranch Hand

Joined: Mar 21, 2001
Posts: 169
Originally posted by Adam Price:
I am working on 4b.

Congrats! It will be over one of the days sorry, "soon"!
And you will have learnt sooooo much Believe me!

Here's my help:
Originally posted by Adam Price:

My nitpicker says: Notice how there's a bunch of similar code in your method? (...) I wonder if you could simplify your method if you went through that process only once? (You'd have to call the method more than once, of course, and pass it the parameters it would need for each case then...)

The nitpicker is trying to tell you something special here ...
You're repeating yourself in your method too often.
Can't you just call it a few times with different parameters?

Any direction?

Think about what your head does when you try saying a really big number ...

BTW: I didn't print the comma but I passed the assignment.



It was suggested that I make identifiers (...) instead of typing out a bunch of zeros ([int oneMillion = 1000000. Given that, since they are used only in the second method, why is it preferable to pull them out of the method and have them be static finals for the whole class?

Get used to doing this, especially as the final solution could need the constants in the main() method and your instance methods.

My main method modelled what I understood my mind was doing when I saw a really big number (you know, reading from left to right but making sure I knew how many digits were on the right of the number ...). The instance methods just did the "nitty gritty" stuff I don't really need to think about.

I hope this didn't help too much You can come back and ask the others to confuse you too

Stuart
[ January 28, 2006: Message edited by: Stuart Goss ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
It sounds like your nitpicker is trying to help you be a little less "long winded" while still being "crystal clear". If the code for billions, thousands and millions is almost identical (for example, "appends the name of the period followed by a comma if necessary"), and only the values are different, perhaps you need another method, one that maybe passes in the different values (for example, the name of the period).


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Adam Price
Ranch Hand

Joined: Nov 11, 2005
Posts: 95
Originally posted by Marilyn de Queiroz:
It sounds like your nitpicker is trying to help you be a little less "long winded" while still being "crystal clear". If the code for billions, thousands and millions is almost identical (for example, "appends the name of the period followed by a comma if necessary"), and only the values are different, perhaps you need another method, one that maybe passes in the different values (for example, the name of the period).


The difference between the code for different periods is that they all have their own way of determining whether they need a comma (since the necessity of a comma is determined by the existence of values of succesively lower registers. I suppose I could just drop the comma altogether, as Stuart did.......
Stuart Goss
Ranch Hand

Joined: Mar 21, 2001
Posts: 169
I suggest you to forget the comma, Adam ...
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
What if you drop the comma for now and add it back in if/when it is less complicated to do so.
Adam Price
Ranch Hand

Joined: Nov 11, 2005
Posts: 95
Originally posted by Stuart Goss:


My main method modelled what I understood my mind was doing when I saw a really big number (you know, reading from left to right but making sure I knew how many digits were on the right of the number ...).

You sure about that? Every time I read your post, this jumps out at me. I don't do that. Starting at the right, I count off groups of three, visualizing where the commas would go, and count groups so I know what to call each one. Then I read the sections between the commas as chunks<1000, not as individual numbers.
Stuart Goss
Ranch Hand

Joined: Mar 21, 2001
Posts: 169
Adam, not sure if you've managed 4b yet, anyway here:

I look at number and think:
"If there are some billions, say them"
"If there are some millions, say them"
"If there are some thousands, say them"
"Say the rest"

(no commas)

Is this giving away too much?

Stuart
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Originally posted by Stuart Goss:
Is this giving away too much?

Stuart


Nope, you're perfecting the art of "Cattle Drive Speak", a special branch of encryption science.

Adam, does that help? Yell first, rather than pulling your hair out on this one - we can get less cryptic if necessary.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Naturally, we've seen a lot of solutions. The backwards solution does work, but it is never as clean as ..... the more popular solutions.
Adam Price
Ranch Hand

Joined: Nov 11, 2005
Posts: 95
Originally posted by Marilyn de Queiroz:
The backwards solution does work, but it is never as clean as ..... the more popular solutions.

This is the part that is giving me trouble. I can think of a half dozen ways of structuring this task. The one I went with first, I chose because it most closely resembles how I read a number.* I can tell that I am being steered away from the approach, but I can't really tell why, so I can't tell which approach to try next. Should I be trying to cut down on identifiers? Go for more, shorter methods? Make it easily extendable? These are all rhetorical questions, but they frame the area where I get tangled up.

That said, I have have had almost no time to myself for a while now, which is the primary reason I am not making any progress.


-Adam

* Stuart - What number is this: 172691111 ?

. . . . . . If you can truly read that left to right, I will concede. What I am forced to do, though, is first count off groups of three, right to left, then say each group. I believe a computer can approach this as you describe - I just don't believe that a human can unless he or she has the numerical-savant upgrade kit installed.
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Hi Adam,

I just found an old thread that has one of the many discussions about Say 4b. Maybe the hints you find here help a little?


Hang in there,
Pauline
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Originally posted by Adam Price:
What number is this: 172691111 ?


It must be one hundred eleven six hundred ninety-one thousand one hundred seventy two million.
Stuart Goss
Ranch Hand

Joined: Mar 21, 2001
Posts: 169
Originally posted by Adam Price:

* Stuart - What number is this: 172691111 ?

. . . . . . If you can truly read that left to right, I will concede.


Ok, what am I doing here in my head?:
- I scan the size of the number
- is it larger than a billion? but smaller than a trillion?
- if so: say that bit
- now, is the rest larger than a million?
- if so: say that bit
- etc.

then I Say, "one hundred seventy-two million six hundred ninety-one thousand one hundred eleven".

Sorry for the late reply, my hard-drive died.

- Stuart
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 4b structure
 
Similar Threads
Java-4b Please
Say 4b question
Question regarding Assignment 4b
Where to split methods (Say 4b)
Java-4b technique