aspose file tools*
The moose likes Beginning Java and the fly likes How close am I in getting this program right? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How close am I in getting this program right?" Watch "How close am I in getting this program right?" New topic
Author

How close am I in getting this program right?

bue curt
Greenhorn

Joined: Dec 25, 2009
Posts: 14

First of all, Happy new year!!!



Hi, I'm beginner learning programming . The goal of this java program is to convert an integer ranging from 0-999 to its word equivalent, and it should ask the user if he/she still wants to enter a new number(I have no idea how can I make that possible )
I'm not even sure of this codes are close enough to attain that goal.

Can you point out my errors? What should I change? Am I getting there?

Any help is appreciated.

Have a nice day!

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
For repetition until somebody writes "stop" try this old thread and see if you can get it faster than Robin did.
bue curt
Greenhorn

Joined: Dec 25, 2009
Posts: 14
Campbell Ritchie wrote:For repetition until somebody writes "stop" try this old thread and see if you can get it faster than Robin did.


We are not allowed to use that code.
Switch,if,if else,while,do while,for loop are the only allowed method.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

bue curt wrote:
I'm not even sure of this codes are close enough to attain that goal.

Can you point out my errors? What should I change? Am I getting there?


Does it compile? And if it doesn't what is the error?

Does it run? And if it does, what happens?


Generally, the easiest way to find an error is to figure out what is wrong first.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
bue curt
Greenhorn

Joined: Dec 25, 2009
Posts: 14

Does it compile? And if it doesn't what is the error?

Does it run? And if it does, what happens?


Generally, the easiest way to find an error is to figure out what is wrong first.

Henry


The build is successful but it does not run.

Harold Lime
Ranch Hand

Joined: Jul 20, 2009
Posts: 38
The code you have is overly complicated IMO.

I'd break down how you would do this on paper first, then figure out how to do that with Java.

Something like:

- Read input
- Is it a number?
- Is it the specified range?
- Is is a 3 digit number?
- Does it end with a number below 21?


Or you could just create a 1000 element array and fill it with all the answers.
Ashish Schottky
Ranch Hand

Joined: Dec 29, 2009
Posts: 93
Can you provide me with an example of the output.
e.g. 1500 can be 'Fifteen Hundred' or One Thousand Five Hundered.
So if you give me the desired out put may be I can help you.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

bue curt wrote:


Well... What do you think this error message is saying? For a beginner, it may be daunting, but take a shot at it... It is actually quite easy. Getting comfortable with reading these errors messages, is needed in getting good at finding the errors.

Henry
Harold Lime
Ranch Hand

Joined: Jul 20, 2009
Posts: 38
The build is successful but it does not run.



I've removed what I first wrote.

Check this: http://java.sun.com/javase/6/docs/api/java/io/BufferedReader.html to see how you might go about getting input from the user.
bue curt
Greenhorn

Joined: Dec 25, 2009
Posts: 14
Ashish Schottky wrote:Can you provide me with an example of the output.
e.g. 1500 can be 'Fifteen Hundred' or One Thousand Five Hundered.
So if you give me the desired out put may be I can help you.


The range of number is 0-999 only.
so
124 will be one hundred twenty four


Or you could just create a 1000 element array and fill it with all the answers.


That is my last option. I hope I would never do it
bue curt
Greenhorn

Joined: Dec 25, 2009
Posts: 14
I have the working code, but instead of word equivalent it prints numbers.




Here is the output for this program, w/c is incorrect



Any reply will be appreciated, thank you
Harold Lime
Ranch Hand

Joined: Jul 20, 2009
Posts: 38
I'd start again, maybe with the code below, I think that all those switch statements are sending you in the wrong direction.

And as I said earlier, the code should probably be doing something like:

- Read input (done)
- Is it a number? (done)
- Is it the specified range? (easy)
- Is is a 3 digit number? (easy)
- Does it end with a number below 21? (easy, why is this important though?)

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

@Harold: Please be very careful when providing complete or even partial solutions. One of our goals here is to get people to do all of their own work, experience their own triumphs and failures, learn how to learn, and so on. I'm leaving your code (someone else may not), but it's on the edge of what I'd consider "too much information". (I'm also a bit more draconian about this than some here.)
Harold Lime
Ranch Hand

Joined: Jul 20, 2009
Posts: 38
David Newton wrote:@Harold: Please be very careful when providing complete or even partial solutions. One of our goals here is to get people to do all of their own work, experience their own triumphs and failures, learn how to learn, and so on. I'm leaving your code (someone else may not), but it's on the edge of what I'd consider "too much information". (I'm also a bit more draconian about this than some here.)


Fair point, although it's really a rejigged (and condensed) version of the code originally posted - I didn't actually add anything.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
bue curt wrote: . . .
We are not allowed to use that code.
Switch,if,if else,while,do while,for loop are the only allowed method.
As far as I can remember, it was simply a while loop . . . once Robin got her act together to read the thread.
Misha van Tol
Ranch Hand

Joined: Jan 02, 2010
Posts: 56

If you're allowed to use array's you don't need the switch / case structure. And no, I don't mean one array of a thousand items. Three array's of nine items should be enough.
bue curt
Greenhorn

Joined: Dec 25, 2009
Posts: 14
Misha van Tol wrote:If you're allowed to use array's you don't need the switch / case structure. And no, I don't mean one array of a thousand items. Three array's of nine items should be enough.



meh, arrays aren't allowed. Just woke up, I'm trying make t work
bue curt
Greenhorn

Joined: Dec 25, 2009
Posts: 14
I've have finished the program, thanks everyone. It can output the world equivalent of numbers from 0-9999. But, I've rechecked my notes and it says that it should output numbers from -9999 to 9999. do i have to make new switch statements for the negative numbers? or I could simply do -number * -1= number then print with word negative?
Is that possible?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
Well done getting the positive numbers to work

For negative values, use the word "minus" . . .
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

Unrelated to the solution,

Why do you have restrictions to use switch,arrays etc. ?
I personally feel the program is much simpler than what you are going for ...


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11402
    
  16

Sometimes, assignments are given to get the student to learn how to use certain features, like case statements, or for loops, or certain data structures. By limiting what they are allowed to use, the instructor can better show the strength and weaknesses of various data types or control structures.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

fred rosenberger wrote:Sometimes, assignments are given to get the student to learn how to use certain features, like case statements, or for loops, or certain data structures. By limiting what they are allowed to use, the instructor can better show the strength and weaknesses of various data types or control structures.

Given that the assignments are properly choosen which in my opinion, is not for the OP's question.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How close am I in getting this program right?