Advertisement
ultravibez

HashMap Main

Nov 4th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Menu m = new Menu();
  9.         Scanner in = new Scanner(System.in);
  10.         int option = 0;
  11.         User user = null;
  12.         while (option != 4) {
  13.             if (user == null) {
  14.                 System.out.println("Please enter your option:");
  15.                 printMenu();
  16.             } else {
  17.                 printMenuLoggedIn(user);
  18.             }
  19.             option = in.nextInt();
  20.             switch (option) {
  21.                 case 1:
  22.                     m.signUp();
  23.                     user = null;
  24.                     break;
  25.                 case 2:
  26.                     user = m.login();
  27.                     break;
  28.                 case 3:
  29.                     if (user == null) {
  30.                         System.out.println("Bye!");
  31.                         option = 4;
  32.                     } else {
  33.                         m.changePassword(user);
  34.                     }
  35.                     break;
  36.                 case 4:
  37.                     System.out.println("Bye!");
  38.                     break;
  39.                 default:
  40.                     System.out.println("Invalid option");
  41.                     break;
  42.             }
  43.         }
  44.     }
  45.  
  46.     //Printing this menu when NO user is logged in.
  47.     public static void printMenu(){
  48.         System.out.println("1. Sign up.");
  49.         System.out.println("2. Log in.");
  50.         System.out.println("3. Exit.");
  51.     }
  52.     //Printing this menu when user IS logged in.
  53.     public static void printMenuLoggedIn(User user){
  54.         System.out.println("Welcome " + user.getUsername() + "!");
  55.         System.out.println("Please enter your option:");
  56.         System.out.println("1. Sign up.");
  57.         System.out.println("2. Log in.");
  58.         System.out.println("3. Change password.");
  59.         System.out.println("4. Exit.");
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement