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 Java-4a Please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Java-4a Please" Watch "Java-4a Please" New topic
Author

Java-4a Please

Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
I received 2nd nitpicked reply from Ms Marilyn. She asked me to do more hardwork on the above assignment and turning me to the proper way to complete the job and i think in that way my source code length will reduce.
I made my program using arrays, substring and case statements which works fine but its length is more than 100 lines. But she wants me to make the assignment using wacky maths functions and if-else statments.
So could u please let me know what is that simple maths function to dig out the right string from the 2 arrays in which i stored my counting in strings (1 to 20 in 1 string and 30 to 90 decimal-wise in another string) and now i hv to use math methods to perform the job. Please suggest me.
Thanks in advance.
~Rashid
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
Rashid,
There is no magical math method/class than will solve this for you.
You must use division (/) and remainder (%) operators.
The way to take solve this "problem" is to sit down and write how the different possible numbers that can be entered are represented as "words".
IE :
21 twenty-one, 1 twenty and one seperated by a -
56 fifty-six, 1 fifty and a six seperated by a -
Another way to look at it is :
21 = 2 tens with a remainder of 1
56 = 5 tens with a remainder of 6
But we dont say : two tens and one or five tens and six.
So you are on the right track with you two seperate arrays
Also look ahead to Java-4b. You are not coding it yet but you are building the foundation for the solution for Say b.
See if your solution for the "small" part of big numbers will work.
723 788, seven hundred and twenty-three, seven hundred and eighty-eight
Notice how the solution for Java-4a comes back in big numbers Thats why they make us to it in two phases.
Hope I helped you a bit i find it hard to explain something without giving away to much, actually I find it hard to explain anything .
But Rashid the less one gets spoon fed the more one will learn, good luck.

[This message has been edited by Johannes de Jong (edited April 14, 2001).]
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
Thank u very much for your tips Johannes i'll try my best to do that using your guidelines during this weekend.
wish u a good weekend
kind regards
Rashid
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
How about this idea, if the number is less than 20, use an array of 0 to 19 to show the results.

Otherwise:� show the tens stuff and if there is a ones digit, show a hyphen and the one digit.

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

Joined: Jan 16, 2001
Posts: 349

How about this idea, if the number is less than 20, use an array of 0 to 19 to show the results.
Otherwise: show the tens stuff and if there is a ones digit, show a hyphen and the one digit.

Dear Marilyn, my code does work on the first part of your suggestion but it is getting hard to code the other part i.e. to link the 2nd array to 1st array but without "zero" and the logic is not getting cleared as yet.
Dear Johannes, how could i use (%) and (/) operators to serve the purpose. please suggest some examples.
Please note that this program works fine with case statements but nitpicker asks me to do this using if-else statements.
Or is there anyother way to make this program.
[This message has been edited by Rashid Ali (edited April 18, 2001).]
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
Hi Rashid,
If you take 56.
j = 56 / 10 ; // j = 5
k = 56 % 10 ; // k = 6
Use these numbers to point to the correct array entry.
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
Thanks Johannes
But the problem is that i have to use some iteration process which automatically check the number from command line and after calculating pickup the right word from the both arrays list.
is some other example for this purpose. i think i am bothering u much but be patient.
Thanks for all your messages sir
Rashid
pete hesse
Ranch Hand

Joined: Aug 29, 2000
Posts: 44
Rashid,
You don't need to use a case statement. An if...else will work fine.
The suggestions that have been made up to now, combined, will get you there. (You stated yourself that you understood one part!) Just be patient and keep working. You'll get it.
Pete
[This message has been edited by pete hesse (edited April 19, 2001).]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
Get and parse the number from the command line
Get the tens digit by calculating
Get the ones digit by calculating

If
the number is less than 20, pick the right word from the array containing the ones and teens

Otherwise
Pick the right word from the array containing the tens
If the ones digit is not zero, print a hyphen and pick the right word from the array containing the ones and teens
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
Thanks Marilyn and Johannes for your kind messages and help in finalizing my assignment.
Pete, when i reviewed my program with patience yesterday, then i could be able to understand the logic involved and finalized my assignment successfully in the same way as you mentioned but it spread over 107 lines and it works fine.
Thanks again to all of you
Rashid
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
Again here :
I made my program Java-4a using the code such as:

The above is a piece of code just to give you an idea of logic.
May i know that is this okay or i will have to made it using & and % math tricks.
FYI, This program work fine as per the desires of this assignments.
Please advise to complete it in the right way. But using the above code logic.
Thanks
Rashid
[This message has been edited by Rashid Ali (edited April 27, 2001).]
[This message has been edited by Rashid Ali (edited April 27, 2001).]
[This message has been edited by Rashid Ali (edited April 27, 2001).]
Umesh Khosla
Greenhorn

Joined: Apr 24, 2001
Posts: 10
Dear Rashid ,
I think I can be of help try this code . this is for 4b think u will be able to find a soln for 4a also. Rest of us pls give suggestions. the identation is getting all lost suggest how to put code in aproper manner.

Marilyn added code tags and removed some code to protect future participants.

[This message has been edited by Marilyn deQueiroz (edited April 26, 2001).]
Richard Boren
Ranch Hand

Joined: Mar 01, 2001
Posts: 233
Umesh, DO NOT PUT COMPLETE CODE IN YOU POST. Only pseudo code and code snippets. Otherwise you will ruin the learning experience for others. Please remove the code form your posts, else a sheriff will.
It is good to help others, but bad to do it for them.
[This message has been edited by Richard Boren (edited April 26, 2001).]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
Rest of us pls give suggestions. the identation is getting all lost suggest how to put code in aproper manner.
You need to put it in code tags that look like [ code ] [ /code ]
(without the spaces).

Echoing Richard's statement, please do not post code here except for very small snippets or pseudocode. Don't rob other students of an education.
Umesh Khosla
Greenhorn

Joined: Apr 24, 2001
Posts: 10
Sorry, People would not happen again , I am a bit over enthusiastic about things...
Richard Boren
Ranch Hand

Joined: Mar 01, 2001
Posts: 233
That's cool
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
My question is still there. could my code be accepted ?
please advise after reading my last post.
thanks.
Rashid
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
Rashid look at your code carefully you repeat a lot of code.
If twenty , if thirty etc. If you divide the number by 10 you get 2,3,4, etc. you can use that to point to the correct position in the specific array.
Read the piece by Paul http://www.javaranch.com/drive/baby.html and you might understand what I mean.
Good luck

[This message has been edited by Johannes de Jong (edited April 28, 2001).]
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349

Get and parse the number from the command line
Get the tens digit by calculating
Get the ones digit by calculating
If
the number is less than 20, pick the right word from the array containing the ones and teens
Otherwise
Pick the right word from the array containing the tens
If the ones digit is not zero, print a hyphen and pick the right word from the array containing the ones and teens

Thanks very much Marilyn and Johannes for your great support in finallizing my 4a assignment which i yesterday completed as per the above instruction from Marilyn. Both Marilyn and Johannes helped me a lot !
Thank you.
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
Again need your advise!
In response to my 4a attmpts Marilyn asks me to use some proper name for variable which i used in calculation using '/' and '%' operators instead of i, j, k, to pick out the right variable from arrays.
These names are not coming in my mind what to use in this program. Can i be suggested for the same if possible.
Thanks
Rashid
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
Thanks for your kind words Rashid
When you use a variable name think of what is is used for. In this case your i,j,k are used as index's. Ask yourself what is in the the array you are indexing ie. what is it used for..
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349

Marilyn suggest:
"Notice how you print tensName[ divArgs ] ) in both
the else if block and the else block.
Maybe you can think of a way to consolidate this code."


My 4a is in the final stage, only the above clarification is required and after that i am sure it would be accepted.
Can I have a suggestion that how can i consolidate my code as desired by Marilyn. Hope from the above suggestion you could understand the scenario of my program flow.
I don't show my code here as it is against the forum requirement, but hope for your understanding.
Rashid
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
Rashid, Marilyn suggests you look at what the else if & else have in common. Try and put that in a method and call the metod.
Amber Woods
Ranch Hand

Joined: Mar 28, 2001
Posts: 111
Hi Rashid,
If you are printing the same line in both the if/else block. Why not just print it once and then do a check for the rest of the number (ones digit).
Hope that helps and doesn't give away too much.
Amber

"Happiness is a way to Travel, <b>Not</b> a Destination" -- Unknown
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
Thanks Johannes and Amber for your suggestions.
Now my program works fine in that way.
Rashid
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java-4a Please
 
Similar Threads
My exam results: 93% or maybe 98%. Big mistery to me.....
Doubt in Arrays.asList()
Is there a performance implication ??
Help on String methods!!!
How to move cursor to next row?