• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
Ranch Hand
Posts: 56
Android Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We're glad to have your help, David. Feel free to add to a thread anytime.
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic