File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Cattle Drive and the fly likes Assignment 1.4 (Say) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Assignment 1.4 (Say)" Watch "Assignment 1.4 (Say)" New topic

Assignment 1.4 (Say)

Jesse Thompson

Joined: Nov 17, 2000
Posts: 10
This is my first post... I was told by the nit-picker that I was to utilize this forum or I would by totured by the cattle prod...
I got assignment 1.4 to work fine, but I did not utilize any methods, and it doesn't look all that good (at least to me). Before I submit my work to the nit-picker, I wanted to make my code better..
Please help a new greenhorn...
Here is my code..

// get an int at command line 0-99, and display number spelled out

All help is much appreciated...

[This message has been edited by Marilyn deQueiroz (edited November 27, 2000).]
Allen Alchian
Ranch Hand

Joined: Oct 11, 2000
Posts: 83
I appreciate your dilemma. I too discovered that getting the code to produce the specified result was only a small part of the problem. The real task is to write the program in a way that complies with the Style Guide and is organized in good OOP format. I'm still nursing all those prod wounds following Asmt 1.4.
You could make a method that contains just the code that does the acutal conversion of numbers to text. It may not seem to make much sense to put such a small amount of code into a method, but that, I guess, is the idea of having methods...making each method do one definable task.
Good luck, and don't let that prod get you too often!
[This message has been edited by Allen Alchian (edited November 27, 2000).]

Shama Khan
Ranch Hand

Joined: Aug 14, 2000
Posts: 185
The algorithm posted above is so simple. Jesse, you are not handling the dash '-'. you need some more code to handle numbers that end with '0' - for 90 you want 'ninety' but for 99 you want 'ninety-nine'.
I complicated mine to the max.
1. I am taking the input as a string,
2. then putting it in an array of int in a reverse order.
3. Upon finding out the size of the array, I have different code for a 3 digit # versus two digit and so on.
4. oh, and the teens are contained within the 'ones' array.
5. If a number is less than 20 then ones[number] is printed. if a number is greater or equal to 20 then I print tens[number's 1st digit] + ones[number's 2nd digit]
I may have complicated it because I was thinking about the extra credit assignment from the beginning. After all this rambling, my question is:
What takes up more resources -
comparing contents of an int array or
using mod and division?
PS: I don't think you're supposed to give the solution away in terms of pasting your code in. You should try pseudo code like I did.
[This message has been edited by Shama Khan (edited November 27, 2000).]
[This message has been edited by Shama Khan (edited November 27, 2000).]

Jesse Thompson

Joined: Nov 17, 2000
Posts: 10
Thanks for all the help, I sure need it. Good idea to put the teens and ones array in the same array.
I have a hard time using methods for such simple tasks, but I know I need to start getting use to it.
I've noticed that other people were able to put their code in a different format from the rest of the text. Is this how I do this???

If this is correct, do I just put (copy and paste) the code sniplet within the second print command??
I didn't realize that we were not suppose to put our code on the forum... I guess I'll get a good poking with the cattle prod.
Zzzzaappp... Ouch...
Jesse Thompson

Joined: Nov 17, 2000
Posts: 10
Oh, I see how that code thing works now..
I answered my own question..
paul wheaton

Joined: Dec 14, 1998
Posts: 20973

At this point, what takes up more resources is not as important as what is more readable.

permaculture Wood Burning Stoves 2.0 - 4-DVD set
I agree. Here's the link:
subject: Assignment 1.4 (Say)
It's not a secret anymore!