简体   繁体   中英

Hiding System.out.println until admin logs in

So I am a beginner to the Java world, I know some syntax and can make simple programs but that is about it. So I have an assignment which is 90% complete. Its a bookstore with the options Register - Sign in - View Books - View Purchase History. I have completed these but the one I am stuck on is the administrative capabilites.

What was asked of us was if someone signs in using the admin username then 2 more options in the menu should become visible. So as it stands it would be pretty much like this.

  1. Register
  2. Sign In
  3. View Books
  4. View History
  5. Quit

In my Sign in method after the user enters in the username I figure do a If(username!="admin") "Continue as a normal user" else display original menu with the 2 new menus like so

  1. Register
  2. Sign Out
  3. View Books
  4. View History
  5. Manager Users
  6. Manage books
  7. End

So my problem is how to hide these 2 options or display them when an admin signs in.

Now I do not want anyone to do this for me, but any type of guidence would be great.

Thanks in advance.

Brandon

something along the lines of this

if(username.equals("admin")) {
    System.out.println("option 6");
    System.out.println("option 7");
}

Essentially you're checking if someone is an admin and if they are then you give them the extra options. You will have to make sure though when you are actually getting the user input that they don't enter one of the admin options though. Just because the menu doesn't display it doesn't mean you don't have to check for it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM