Advertisement
Guest User

Untitled

a guest
May 1st, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static Scanner sc = new Scanner(System.in);
  6.     public static String[] acc = new String[2];
  7.     public static String key = "quit";
  8.     public static void main(String[] args) {
  9.         int a = 0;
  10.         do {
  11.             System.out.println("Would you like to log-in(1) or register[2]?");
  12.             a = sc.nextInt();
  13.         } while( a > 2 || a < 1);
  14.  
  15.         System.err.println("If you wish to close the terminal - type 'quit' in both username and password!");
  16.         if(a == 1) Login();
  17.         else if(a == 2) Register();
  18.     }
  19.  
  20.     public static void Register() {
  21.         System.out.print("Please enter a username: ");
  22.         acc[0] = sc.next();
  23.         System.out.print("Please enter a password: ");
  24.         acc[1] = sc.next();
  25.         if(acc[0].equals(key) || acc[1].equals(key)) System.err.println("Terminal Shut Down!");
  26.         else {
  27.             System.out.println("You have successfully registered, " + acc[0] + "!");
  28.             Login();
  29.         }
  30.     }
  31.  
  32.     public static void Login() {
  33.         String name, pass;
  34.         System.out.print("Please enter username: ");
  35.         name = sc.next();
  36.         System.out.print("Please enter password: ");
  37.         pass = sc.next();
  38.  
  39.         if(name.equals(acc[0]) && pass.equals(acc[1])) System.out.println("Welcome, " + acc[0] + "!");
  40.         else if(name.equals(key) || pass.equals(key)) System.err.println("Terminal Shut Down!");
  41.         else {
  42.             System.out.println("Account not found! Please register!");
  43.             Register();
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement