aspose file tools*
The moose likes Beginning Java and the fly likes Having issues with sub menu causing main menu to not exit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Having issues with sub menu causing main menu to not exit" Watch "Having issues with sub menu causing main menu to not exit" New topic
Author

Having issues with sub menu causing main menu to not exit

Christina Bremmerman
Ranch Hand

Joined: Feb 02, 2012
Posts: 33
Well I'm back again, this time less frazzled and well rested and I'm having some issues with my menu and sub menu.
Basically what's happening is my main menu has an exit, and it works fine when I don't get into the sub menu, but if I go into the sub menu once I exit back to the main menu it's making me choose my exit selection multiple times(it seems like it depends on how many things I do in my sub menu as to how many times I will have to select exit from the main menu before the run stops.
Here is the code for the menus, I don't think that there is anything in the rest of my code that would cause this.


Daniel Croft
Greenhorn

Joined: Feb 16, 2012
Posts: 21

I believe this is because you're using multiple scanners on System.in so your outer scanner "scanner 1" grabs your first input that sends your program to the submenu. Then the submenu "scanner 2" grabs the next input say it's "pie". When the submenu returns, you read the input from System.in again with "scanner 1". But "pie" is still queued up in "scanner 1". You should make sure that you only use one scanner object and either pass it around to each method or put it in a class where everything in your code can access it easily.
Christina Bremmerman
Ranch Hand

Joined: Feb 02, 2012
Posts: 33
Hmm, yeah my knowledge of the scanner isn't much, in class it's basically like oh just use this.
And I usually put my

before everything instead of inside the methods like that, but on the last lab my instructors version had it inside the method, so this time that's how I did it.
I went back and changed it so that there aren't any scanners created inside of any of the methods it's just up at the beginning of the class and the program is working exactly the same as far as I'm noticing.
Daniel Croft
Greenhorn

Joined: Feb 16, 2012
Posts: 21

Just to clarify, are you still using more than one Scanner, or are you making all calls to the same Scanner now?
Christina Bremmerman
Ranch Hand

Joined: Feb 02, 2012
Posts: 33
Nope just one scanner outside of all my methods up at the top chillin with the variables. Only scan no scan2
Daniel Croft
Greenhorn

Joined: Feb 16, 2012
Posts: 21

Ok, so if I understand your code you call ATM() which if menu == 1 calls createAccount() which I assume calls accountMenu() at some point.

Then if you select "4 - Logout of account." you call ATM() again. I think you probably meant to return here instead so you can get back to your first ATM() call instead of spawning a new one.
Christina Bremmerman
Ranch Hand

Joined: Feb 02, 2012
Posts: 33
Aaah so that is it.
It's always something so simple.
Thanks for your help!
Daniel Croft
Greenhorn

Joined: Feb 16, 2012
Posts: 21

No problem, glad I could help. Google always links me to this site; it's so useful I figured it was about time I started giving back.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39755
    
  28
Google have got it right, then? Welcome to the Ranch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Having issues with sub menu causing main menu to not exit