1,105,229 Community Members

Simple Console GUI problem about navigating the user

Member Avatar
DevNet
Newbie Poster
5 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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..

Member Avatar
zeroliken
Nearly a Posting Virtuoso
1,222 posts since Nov 2011
Reputation Points: 79 [?]
Q&As Helped to Solve: 216 [?]
Skill Endorsements: 15 [?]
 
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)

Member Avatar
DevNet
Newbie Poster
5 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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. :)

Member Avatar
rushikesh jadha
Junior Poster in Training
89 posts since Dec 2011
Reputation Points: -6 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 0 [?]
 
-3
 

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

Question Answered as of 2 Years Ago by zeroliken and rushikesh jadha
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: