jQuery in Action, 3rd edition
The moose likes Cattle Drive and the fly likes creating a method  / Assignment Java-4a (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 "creating a method  / Assignment Java-4a (Say)" Watch "creating a method  / Assignment Java-4a (Say)" New topic

creating a method / Assignment Java-4a (Say)

ione walker
Ranch Hand

Joined: Apr 19, 2001
Posts: 31
on the cattle Drive Assignment Java-4a (Say)
one of the "things you need to know" is
how to make your own methods.
I was able to do the assinment without makeing a method.
In fact when I tried the thing no longer worked.
I would like any sugestions on improvements to the code.
/*Write a program that will read in a number from 0 to 99 and spell out that number. The program must also report any values that are out of range.
In other words, I want to type
java Say 22
and see
public class Say
//read in num from user 0 to 99
// spell outin text the entered number
public static void main( String[] args )
// this is the string with the user entered number in it
//index for ones place array

//index for tens place array
// this is the interger with the user entered number in it
//input too low
//input too high
//input 1 diget & teens
//creat the arrays that will give the spelling of the number

thanks for your help in clearing this up for me.
Ione Walker
Troy MI
(Code removed by Marilyn)
[This message has been edited by Marilyn deQueiroz (edited April 30, 2001).]

=======================<BR>Ione Walker<BR>walkeri@usa.net<BR>========================
Richard Boren
Ranch Hand

Joined: Mar 01, 2001
Posts: 233
Hi Ione,
First you shouldn't put your code here, only pseudo code or snippets. When you do put actual code snippets in your post wrap them with UBB Code code tags, it makes it easier to read the code.
You do a lot of processing before checking to see if the number is within range. Why not do that first. Also notice you print "Number must be an iterger greater than 0 & less than 100" in two places why not do it once, loose the else.
If i is the int for the numOnes[] then way do you need the num variable.
While I'm at it, I'm not a nitpicker; however, I think you should use more meaningful names for your variables. Instead of i why not ones.
I don't think you will ever get "zero" to print because you check to see if num is greater than 0 before you print. Also I don't see how you are getting any of your ones to print since you are loading ii with the tens position; i.e., you are passing substring() the position 1 which should be for the tens not the ones.
You don't need to check num and then use i and/or z to retrieve the word number from the array.
As for the method you have a lot of code in your main which could be moved to a method making main much more readable. All you really need in main is the range check. Move all the logic for getting the worded number to its own method like: static void figureOutAWordForThisNumber( String s ) {}.
Hope this helps. And thanks for the learning experience
[This message has been edited by Richard Boren (edited April 30, 2001).]
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
Usually I prefer that you don't post code here. If you post great code, you will be robbing others of an education.

"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

Joined: Jul 22, 2000
Posts: 9059
Don't worry about creating a method in Java-4a. You will create a method when it is necessary, not just for the sake of creating a method.
I agree. Here's the link: http://aspose.com/file-tools
subject: creating a method / Assignment Java-4a (Say)
It's not a secret anymore!