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: 32708
4
posted
0
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
posted
0
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.
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
posted
0
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
posted
0
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.
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.
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
posted
0
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
posted
0
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?)
@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
posted
0
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: 32708
4
posted
0
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.
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
posted
0
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
posted
0
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?
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.
Never ascribe to malice that which can be adequately explained by stupidity.
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.