• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

How close am I in getting this program right?  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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!

 
Marshal
Posts: 64493
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For repetition until somebody writes "stop" try this old thread and see if you can get it faster than Robin did.
 
bue curt
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
author
Posts: 23832
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
bue curt
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23832
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?)

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Marshal
Posts: 64493
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 56
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 64493
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done getting the positive numbers to work

For negative values, use the word "minus" . . .
 
Bartender
Posts: 2278
95
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...
 
lowercase baba
Posts: 12745
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
salvin francis
Bartender
Posts: 2278
95
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
The knights of nee want a shrubbery. And a tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!