• 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-4b Please

 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can i get step-wise suggestion how to go throgh with 4b. My 4a is going to finish and i think i will have to extend this assignment to work with 4b.
Please advise.
~Rashid
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rashid,
4b is an extension of 4a. Look for a pattern and think what makes 100 different from 100,000 different from 100,000,000 and what makes 1 different from 1,000 different from 1,000,000 and so on.
Hope I didn't confuse you or give to much away.
 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Richard for your reply.
I would also like to get the others point of view which could further help me to complete 4b please.
I am still working on it. there is some progress. Now my program reads no. and say that value between the range from 100 to 919 but this just work between 'xx1' to 'x19' as this is showing my first array's words such as:
One Hundred One ...
One Hundred twelve ...
One Hundred Ninetten
for the others values this program doesn't response and show Array out of bounds ... message. Even though i have correctly point out the correct position of 2nd array but as its value increase after x19 it show the above error message.
Still working on the solution will let u know the further progress in the meanwhile your suggestions are welcome
Hope my message doesn't confuse you.
Awaiting response !!!
Rashid
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wow
I have also sent Say4a off to be nitpicked and am looking forward to trying my humble programming skills on 4b.
 
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I sent 4B off today. It was a lot of fun to work on that program. My recommendation build a different method for each series up and find what's common with those methods. That really helped me tackle the program. I haven't seen my nitpicks yet, but I am looking forward to reading them. Keep us posted on how you do.
Matthew Phillips
 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rashid,
I've just sent in my second attempt at 4b - it's been quite an experience...
While testing different versions of my attempts, the error message Array out of bounds came up a few times too. Usually the problem was that a value passed to the array was bigger than the number of array elements. This had been caused because the program had gone through some calculations to produce the value that was sent to the array, but not in the way I had expected, so a number that was too big for the array resulted.
Fortunately, the error message gave the value that didn't fit in the array. I used this to go back step by step and see how the heck it got calculated, (lots of eye-opening surprises there ) and then corrected the program so that (hopefully) it didn't happen again.
Hope this helps.
Pauline

[This message has been edited by Pauline McNamara (edited May 06, 2001).]
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rashid,
This might be redundant given the other posts, but it's worth keeping in mind that the phrases we use to say (for example) 123, 123456, and 123456789 have a lot in common, and that these commonalities can be exploited in writing your methods.
On the same theme, I suspect that while we need to write multiple methods, we don't need to write so many methods that we end up with an absurdly long, sinuous coil of code.
Hope this helps.
Adam
 
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java-4b is a difficult exercise because it traps both the experienced and inexperienced programmer.
The inexperienced has trouble identifying the pattern of the Base 10 numbering system, while the experienced programmer leverages code that's too complex.
I wrote several completely different programs prior to unleashing my first attempt at Java-4b on Marilyn. Take your time and remember the KISS priciple.
"Inside every complex program is a simple program trying to get out.
I don't know who said it first, but it is true with Java-4b.

Mike
[This message has been edited by Michael Pearson (edited May 07, 2001).]
 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear folks thanks you all for your messages.
My problem is the same as posted by McNamara and i have still not overcome it:


While testing different versions of my attempts, the error message Array out of bounds' came up a few times too. Usually the problem was that a value passed to the array was bigger than the number of array elements. This had been caused because the program had gone through some calculations to produce the value that was sent to the array, but not in the way I had expected, so a number that was too big for the array resulted.


Can i have some suggestions to sort it out.
Actually, I've not been able to pick a number from 'x20' to 'x99' which is from my 2nd array method. But the nos. between 'x1 to x19' shows correctly by the program as this is from my first array method and shows 'array index out of bound' message while i try to pick nos. from 2nd array. Please advise.
If u need further info pls post message here.
Rashid

[This message has been edited by Rashid Ali (edited May 08, 2001).]
 
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rashid try the following, put a System.out.println( xxx ); after you calculate the index and just before the instruction that causes the ou off bounds error. This way you will see the value and from it you might understand what you are doing wrong.
ps. replace the xxx with you index name
[This message has been edited by Johannes de Jong (edited May 08, 2001).]
 
Adam Vinueza
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rashid,
I got the same problem with my first few attempts at getting 4b to run, though I found out that the problem was *very* easy to fix once I saw what I'd been doing wrong. Discovering the nature of the problem was educational, although I felt a little sheepish about the mistake for a few minutes. There's nothing like writing programs to make one feel like one's forgotten elementary arithmetic!
Johannes's suggestion is a great way to figure out what's gone wrong. Also, if I understand your problem, this remark may also help: calculating the right index in 4a is a procedure not *quite* the same as the procedure calculating the right index in 4b--the numbers involved in 4b are much, much bigger. So you might ask, for example, how one calculates the right index in saying the "456" part of 123,456,789.
 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great Johannes
My problem is solved with your technique which was very common but we sometimes to forget to follow.
Adam you are right sometimes we forget to follow simple arithmatic functions which often create problems. Your observation is right which i faced and come to know yesterday.
Thanks for all of the folks help.
Rashid
[This message has been edited by Rashid Ali (edited May 08, 2001).]
 
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
Hi Folks, It's become clear to me what the KISS priciple means, but what do the letters stand for? keep it simple ...?
Pauline
 
Johannes de Jong
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keep It Simple Stupid
 
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
Thanks,jdj that's what I suspected.
 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now my 4b program is progressing. I am making it using for/else's, / and %. But at this stage I think that i will have to change my thinking and turn my program wrt counting the arguments by applying 'hundred', 'thousand', 'million', 'billion'. I also think that i will have also to count the number of digits in a arguments and then shall have to apply 'hundred', 'thousand'... etc.
Please suggest how did you do at your time. Any advise please to help me to move further.
Thanks
Rashid
[This message has been edited by Rashid Ali (edited May 15, 2001).]
 
Johannes de Jong
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rashid I'll try and explain with an example :

Break the number up in chunks starting left to right.
  • Are there any Billions ? yes 123 of them - print it.
  • Are there any Millions ? yes 456 of them - print it.
  • Are there any Thousands ? yes 789 of them - print it.
  • Any hundreds - no huh what now ?

  • Why left to right. Because that�s how we say it
    For numbers of less than 100 you use what you've created before our friend Say a. Remember billions, millions & thousands also have units of hundreds & units less than a hundred ie. tens twenties etc.
    The golden rule : start with your number entered and decrease it with the number (chunk) just printed.
    Again : 123456789012 after the Billions you will have 456789012 remaining etc. So instead of if/else combinations make a method pass it the number and the unit you are trying to print (billion, million, etc)
    Good luck
    [This message has been edited by Johannes de Jong (edited May 15, 2001).]
 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your message Jo;
How can I *Break the number up in chunks starting left to right*
Can you suggest a short example please.
Sorry for inconvenience.
Rashid

 
Adam Vinueza
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rashid,
123456789012 % 1 billion = 123 with a remainder of 456789012, as Johannes pointed out. And you can get 456 out of 456789012 in more or less the same way, and so on all the way to 012. If I understand Johannes, that's what breaking the number into three-digit chunks is.
 
Johannes de Jong
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
100 % correct Adam. Thanks for fine tuning my explanation
 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank u very much to all of you.
Rashid
 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Again : 123456789012 after the Billions you will have 456789012 remaining etc. So instead of if/else combinations make a method pass it the number and the unit you are trying to print (billion, million, etc)


I have just one more querry please. I have made my input in different chunks as desired.
Now what i want to do is to creat a method as mentioned above so that I can pass no. and unit to it and can try to print billion, million, etc. Can i have suggestion please.
Thanks
Rashid
 
Johannes de Jong
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simply pass the method doing the work a integer value to an array that pints to the correct word ie. billion or simply pass it the word itself.
Good luck
 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again for your help Johannes.
Rashid
 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dear Jo, can you give an example for the above method. Actually i have not been able to apply the above method in my program. please suggest me.
Thanks - Rashid
 
Johannes de Jong
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rashid,
Take a look at JRJC - How To Make Methods. I suggest you print this out and look at it and really understand what Paul is doing.
Good luck
 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been playing around with solving this problem with recursion. Would that be considered over doing it?
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Recursion is really cool, but it is also a breeding ground for trouble.� Maybe not from you, but somebody might later have to mash this code and it could be a challenge for them.

In this particular case an iterative approach works just as well as a recursive approach.
 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear Joseph,
in addition to Marilyn's reply, i have also found the following thread useful in which Paul responds about the recursion, hope it helps:
http://www.javaranch.com/ubb/Forum19/HTML/000404.html
Rashid
 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear folks - i am still stucking with 4b. i shall try to tell you my program flow so that you can suggest me the things i am stucking with:
> i have 4 methods in my program as desired:
- array with numbers 1 to 19
- array with decimal numbers from 20-90
- array with hundred, thousand, million, billion
- the main() method
main() calculates the args and prints the array index in the if/else condition the exact figures this works only from 0 to 999 perfectly but for the other values i am not being able to apply the logic.
There is going talks about making a methods for large numbers separately which handles all the figures. But how can i do that as i have already 4 methods in hand and there is no room for the fifth one.
Please help with broad-heartening dear seniors
Thanks to bear with me.
Rashid
 
Johannes de Jong
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rashid if your solution works I suggest you first pass 4a. Then submit 4b and see what "nitpicks" you get back.
[This message has been edited by Johannes de Jong (edited May 24, 2001).]
 
Joseph Russell
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe I have my code looking pretty good now (non-rucursive method) with one exception. To componesate for the possiblity of a number 11 or 12 digits long I changed my int to a long. Using a long seems unnecessary when there are only two cases that I'll really need it...wait I could overload my methds... suggestions?
~Joe
 
Joseph Russell
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rashid -- I think the best advice is to start over. Sometimes by starting over it frees us from the traps that were caught in.
Look at what Johannes said earlier:


Break the number up in chunks starting left to right.
Are there any Billions ? yes 123 of them - print it.
Are there any Millions ? yes 456 of them - print it.
Are there any Thousands ? yes 789 of them - print it.
Any hundreds - no huh what now ?
Why left to right. Because that�s how we say it


That's the best I can do...
 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Johannes de Jong:
Rashid if your solution works I suggest you first pass 4a. Then submit 4b and see what "nitpicks" you get back.


No Johannes, it is not yet completed ... --- still working on it.
take a look to my last message in which there has also a question.
4a is in a completion stage - doing ready myself for 4b - but stucking with it so far.
Rashid
 
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm working ahead as I have a couple of days off. I'm submitting Java 1b but I have done up to 8 already (though I left 7 with a few bugs still!)
I've managed to do 4b with one method in 66 lines of code ( 7 blank lines and 5 comment lines ) with 33 strings and just one method.
I got to that by taking on board the tip in the assignment - make a big program from smaller ones.
A couple of the posts here seemed right on the same track as me ( especially about breaking up into similar chunks ).
I'm waiting to submit all my assignments in order when I get the OK from the nitpickers. Can I just send it all in?? I'm dreadfully curious about the results of my little home-java 2-day-lock-in session :-D
Terry
[This message has been edited by Terence Doyle (edited June 11, 2001).]
 
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

Originally posted by Terence Doyle:
I'm waiting to submit all my assignments in order when I get the OK from the nitpickers.



That's good.

Can I just send it all in?? I'm dreadfully curious about the results of my little home-java 2-day-lock-in session :-D



Nope. It's against the rules.
You'll have to wait just like everyone else has to wait. Maybe you'll see some ways to improve it between now and then.
 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Code that looks wonderful can often be improved -- especially on Say.
On that assignment my emotions for the nitpicks went from
"You want me to do what??" to
"&*^*& I can't do that" to
"Oh, all right" to
"Huh. That is better."
Paul R
 
Ranch Hand
Posts: 111
jQuery Oracle C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
LOL Me too Paul
reply
    Bookmark Topic Watch Topic
  • New Topic