aspose file tools*
The moose likes Cattle Drive and the fly likes Java-4a (Say) - Starting off on this one.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Java-4a (Say) - Starting off on this one...." Watch "Java-4a (Say) - Starting off on this one...." New topic
Author

Java-4a (Say) - Starting off on this one....

Steve Jensen
Ranch Hand

Joined: Sep 23, 2002
Posts: 126
OK, I think I know what i have to do.
But one thing riles me.
I'm going to need a String array that holds the text values for numbers 1-99.
If that is so, how comes there isn't at least 99 lines of code (I say at least, but the array must have 99 elements in it, so the whole program must be MORE than 99 lines)? Or am I missing something


John Bonham was stronger, but Keith Moon was faster.
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6

I'm going to need a String array that holds the text values for numbers 1-99.

This is where you're off a little. You could make it work like this, but one of the goals of this assignment is to create your own methods.
Can you think of things that get repeated in an array like that? Maybe there's a way to reduce the lines of code you need for arrays.
Of course, you'd need a method to put the right combination of things together...

Cryptically yours ,
Pauline
Steve Jensen
Ranch Hand

Joined: Sep 23, 2002
Posts: 126
Originally posted by Pauline McNamara:

This is where you're off a little. You could make it work like this, but one of the goals of this assignment is to create your own methods.
Can you think of things that get repeated in an array like that? Maybe there's a way to reduce the lines of code you need for arrays.
Of course, you'd need a method to put the right combination of things together...

Cryptically yours ,
Pauline

Right, now..........

I got my program to work the long-winded and silly way. :roll:
But now I want to do it the sensible and efficient way.
I know how to create methods.
But I am at a loss as to what I'd want my method(s?) to do in this case.
Based on the hints I have been told so far in this thread, I'm going to construct an array to hold the values [nought, all the way through, to nine], i.e., [nought, one, two, three, four....etc].
Then, i want to be able to take keyboard input from the user, and charcater by character, read this input - perhaps using a stringbuffer(??).
That is, read one character, and if two characters are entered, then read both of them.
No, sorry, i've lost it. I can't see what i have to do.

David Mason
Ranch Hand

Joined: Jan 21, 2002
Posts: 56

Originally posted by Steve Jensen:

Then, i want to be able to take keyboard input from the user, and charcater by character, read this input - perhaps using a stringbuffer(??).
That is, read one character, and if two characters are entered, then read both of them.

Steve,
Maybe reusing code from java-2 & java-3 (maybe even the Instructor's solution) would help here
Dave
Pauline, I don't know the etiquette here, & mean no offense. Is it OK to add a post when you are already helping ?
[ November 28, 2002: Message edited by: David Mason ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
We're glad to have your help, David. Feel free to add to a thread anytime.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
A method is not required until Java-4b where you're accepting values from zero to 999,999,999,999.

You probably want more than one array. Then you can make combinations of the arrays print out.

You don't need to ask the user for keyboard input like I think you're suggesting. Just include the input like you've been doing for the first three assignments -- on the command line when you run the program.

For example,
java Say 5
output will be
five

or

java Say 95
output will be
ninety-five

Of course, you'll have to match the input with the string(s) in the array(s).
Steve Jensen
Ranch Hand

Joined: Sep 23, 2002
Posts: 126
Originally posted by David Mason:
[QB]
Steve,
Maybe reusing code from java-2 & java-3 (maybe even the Instructor's solution) would help here
Dave
OK, i'll have a bash at it in the morning, while you're all still fast asleep, looking at my previous solutions as I go along.
But if I still can't get very far, I guess i'll jus throw m hands up in the air and plead stupidity.
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Originally posted by Marilyn de Queiroz:
A method is not required until Java-4b ...

Oops, sorry about that Steve.

Maybe a little conditional logic instead...

Good Morning!
Pauline
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
Twenty-one, twenty-two, twenty-three,twenty-four,...
Somethings are redundant in there,maybe, you will need to find a way to decompose the number entered.
Hope it helps you


Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Java-4a (Say) - Starting off on this one....