Win a copy of Design for the Mind this week in the Design forum!
    Bookmark Topic Watch Topic
  • New Topic

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

 
kash khan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Report post to moderator
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?

Scan.jpg
[Thumbnail for Scan.jpg]
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thank you for adding code tags, Mohammed. Unfortunately the code wasn’t indented, otherwise it would have looked a lot better.
 
kash khan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Report post to moderator
Have you been taking lessons from Rob Spoor, Jeff?
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Report post to moderator
I would be very interested to see what you get for “press any key to continue”.
 
kash khan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Report post to moderator
Are you maligning your teaching? Are you sure you mean, “not taught,” rather than, “not taught while I was there”?
 
kash khan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Marshal
Pie
Posts: 20999
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
    Bookmark Topic Watch Topic
  • New Topic