We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,453 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Simple Console GUI problem about navigating the user

Hi guys. I just having a little problem about creating a good console GUI for our homework. My program is just a simple shopping cart program where in we were asked to create a GUI that asks for the user if he is either a ADMIN user or a CLERK user. I made the features of it work already, but I don't know how to loop back again to my "main screen" after an action has been done by the user.

In other words, the user could only process one action per execution of my program. Here's a scenario for example, let's say the user is an ADMIN and he wants to ADD ITEM:
MAIN SCREEN->ADMIN USER->ADD ITEM->EXIT THE PROGRAM.
In this case, the user has no choice but to run the program again.

I want it to be:
MAIN SCREEN->ADMIN USER->ADD ITEM->MAIN SCREEN AGAIN.
In this case, the user is given a choice of adding another item or exiting the program after adding an item already

Here's part of the code from what I've done so far:

Admin ad = new Admin();
Scanner s = new Scanner(System.in);
//my "main screen"
System.out.println("Press [1] to CREATE an Item. Press [2] to REMOVE Item. Press [3] UPDATE Item. Press [4] to EXIT");
                int choice = s.nextInt();
                switch(choice){
                    case 1:
                        //add item
                        System.out.println("Enter item ID: ");
                        int itemId = s.nextInt();
                        System.out.println("Enter item Name: ");
                        String itemName = sc.nextLine();
                        System.out.println("Enter item Price: ");
                        int itemPrice = s.nextInt();

                        ad.AddItem(itemId, itemPrice, itemName);
                        
                        break;
                    case 2:
                        //remove item
                        break;
                    case 3:
                        //update item
                        break;
                    case 4:
                        //exit
                        break;
                    default:
                        break;
                }
                
                }

Hope you could help guys :)

P.S. I also did this in an if-else pattern. But I think doing it in a switch is better..

3
Contributors
3
Replies
6 Days
Discussion Span
1 Year Ago
Last Updated
4
Views
Question
Answered
DevNet
Newbie Poster
5 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

but I don't know how to loop back again to my "main screen" after an action has been done by the user.

You could simply put the whole menu in a while loop that runs while choice is not equal to 4(the exit in your code)

zeroliken
Nearly a Posting Virtuoso
1,346 posts since Nov 2011
Reputation Points: 214
Solved Threads: 205
Skill Endorsements: 14

You could simply put the whole menu in a while loop that runs while choice is not equal to 4(the exit in your code)

Thanks! It's working now. I knew there had to be a simple solution. :)

DevNet
Newbie Poster
5 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

i it solve your problem then please marked this thread as solved.

rushikesh jadha
Junior Poster in Training
89 posts since Dec 2011
Reputation Points: 4
Solved Threads: 11
Skill Endorsements: 0
Question Answered as of 1 Year Ago by zeroliken and rushikesh jadha

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0721 seconds using 2.83MB