aspose file tools*
The moose likes Beginning Java and the fly likes Do not know how to code some cases and exit the loop with Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Do not know how to code some cases and exit the loop with "Enter"

kash khan
Greenhorn

Joined: Feb 01, 2012
Posts: 7
SO this is what i have done





So, we are to write a java application over family income.
A menu of 4 choices, as showed.

If choice is 1, user will be promted to enter the month and then to enter the salary earned.
Total number of person entered should not exceed 8.
An empty entry on the "Enter person" prompt should allow user to break out of the loop.

If choice is 2, user will be prompted to enter the month. Detailed information of the month's salary will be listed.

For example.

Enter month (1 for jan - 12 for dec) :1
Family income for Jan :
Father 2000
Mother 1500

Total family income for the month of Jan is $7800
________________________________________

If choice is 3, the program will generate a list of monthly total salary earned entered for the month so far.

If choice is 4 the program will display goodbye message and exit the program!

ok, 1st of all, i do not know how to break out of the loop by pressing "enter"
after that, lets say if the user chooses to display monthly salary by pressing 2, and chooses to enter a month which he hasnt input his salary for, how do i show the error msg?



[Thumbnail for Scan.jpg]

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
Welcome to the Ranch

Please avoid UPPER-CASE writing and tell us the problem in the thread title. I might be able to go back and edit your post with code tags, and you can see how much better it looks.
You will have to get yourself a pencil and paper and eraser (the latter being the most important piece of hardware!) and write down very very simply how you intend to implement No 2. Leave No 3 out for the time being. You want to do one tiny little thing at a time, and get that to work. Think about No 3 later. Once your description is very simple, you can work out from it how to convert that to code.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
Thank you for adding code tags, Mohammed. Unfortunately the code wasn’t indented, otherwise it would have looked a lot better.
kash khan
Greenhorn

Joined: Feb 01, 2012
Posts: 7
Campbell Ritchie wrote:Welcome to the Ranch

Please avoid UPPER-CASE writing and tell us the problem in the thread title. I might be able to go back and edit your post with code tags, and you can see how much better it looks.
You will have to get yourself a pencil and paper and eraser (the latter being the most important piece of hardware!) and write down very very simply how you intend to implement No 2. Leave No 3 out for the time being. You want to do one tiny little thing at a time, and get that to work. Think about No 3 later. Once your description is very simple, you can work out from it how to convert that to code.

Thanks for the quick reply! i have edited the post already! i wish you could help me with my code as it is very urgent! thank you once again
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

kash khan wrote:it is very urgent!


That is not something you want to mention here. It is totally irrelevant to the problem at hand. Please EaseUp.(⇐click)

Also, you'll do well to follow the advice you've already been given, rather than just reiterating your question.

Good luck!
kash khan
Greenhorn

Joined: Feb 01, 2012
Posts: 7
Jeff Verdegan wrote:
kash khan wrote:it is very urgent!


That is not something you want to mention here. It is totally irrelevant to the problem at hand. Please EaseUp.(⇐click)

Also, you'll do well to follow the advice you've already been given, rather than just reiterating your question.

Good luck!

Ah! my bad! sorry about that! was just impatient as the dead line is up ahead and i'm still struggling
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
kash khan wrote: . . . it is very urgent!
No, it isn’t. We don’t use the word urgent.
thank you once again
You’re welcome
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
Have you been taking lessons from Rob Spoor, Jeff?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
I would be very interested to see what you get for “press any key to continue”.
kash khan
Greenhorn

Joined: Feb 01, 2012
Posts: 7
Campbell Ritchie wrote:
kash khan wrote: . . . it is very urgent!
No, it isn’t. We don’t use the word urgent.
thank you once again
You’re welcome

I didnt know about that, sorry. but now i do, i hope you guys could help me, thanks
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

kash khan wrote:but now i do, i hope you guys could help me, thanks


Campbell gave you some very good advice in the first reply here. As I already pointed out, you don't seem to have followed it yet. If you want more help, your best bet is to follow that advice, and if you get stuck, post your current code (with code tags and indentation) and ask a specific question about what you're having trouble with.

Remember: One tiny piece at a time. Don't write a line of code for the next piece until that first piece is working--not just "compiles", but runs and exhibits correct behavior.

But first: Break the problem down and figure out the steps "by hand."
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
What have you been taught about methods? That long main method looks very bad to me. I believe there is an ideal length for the main method: 1 statement. Everything else ought to move out of that method.
Also, why are you marking so much static? I know a lot of people do that, but it often shows they don’t understand what static really means.
kash khan
Greenhorn

Joined: Feb 01, 2012
Posts: 7
Campbell Ritchie wrote:What have you been taught about methods? That long main method looks very bad to me. I believe there is an ideal length for the main method: 1 statement. Everything else ought to move out of that method.
Also, why are you marking so much static? I know a lot of people do that, but it often shows they don’t understand what static really means.

barely anything been thought about method or arrays. and i thinks this 2 things are very important to execute the program, i m self studying them now at the moment. i'm just short of time.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
Are you maligning your teaching? Are you sure you mean, “not taught,” rather than, “not taught while I was there”?
kash khan
Greenhorn

Joined: Feb 01, 2012
Posts: 7
Campbell Ritchie wrote:Are you maligning your teaching? Are you sure you mean, “not taught,” rather than, “not taught while I was there”?

Sir, its an extra subject, whereby grades dont matter as much but they do make a difference over all. teacher do not care much about it. most students give up and just fail it. but i m not one of those students. the course is based very much on e-learning and thats why i need help. i could probably hire someone to do it for me but i want to learn.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18973
    
  40

kash khan wrote:
Campbell Ritchie wrote:Are you maligning your teaching? Are you sure you mean, “not taught,” rather than, “not taught while I was there”?

Sir, its an extra subject, whereby grades dont matter as much but they do make a difference over all. teacher do not care much about it. most students give up and just fail it. but i m not one of those students. the course is based very much on e-learning and thats why i need help. i could probably hire someone to do it for me but i want to learn.


Which is why we are not going to do this for you. See Campbell original answer again...

Campbell Ritchie wrote:You will have to get yourself a pencil and paper and eraser (the latter being the most important piece of hardware!) and write down very very simply how you intend to implement No 2. Leave No 3 out for the time being. You want to do one tiny little thing at a time, and get that to work. Think about No 3 later. Once your description is very simple, you can work out from it how to convert that to code.


Work out the description, get that to pseudo code, and then get it to code. The key is to get started. Start it. Do it. And when you run into an issue, you'll have more information to ask more specific question.

And of course, we will give hints, but not the answer (so you'll better learn).

Henry

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
Henry Wong wrote: . . . The key is to get started. Start it. Do it. And when you run into an issue, you'll have more information to ask more specific question. . . .
. . . so we can help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Do not know how to code some cases and exit the loop with "Enter"