Advertisement
Guest User

Untitled

a guest
Mar 9th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ViewInfoShow {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7.         ViewInfo myViewInfo = new ViewInfo();
  8.         Patient myPatient = new Patient();
  9.                
  10.         System.out.println(myViewInfo.printLogo());
  11.         System.out.println(myPatient.createUserName());
  12.         System.out.println(myPatient.createPassword());        
  13.        
  14.         login();//run login function
  15.        
  16.     }
  17.    
  18.     public static boolean login()
  19.     {      
  20.         //Import Class Object
  21.         Patient myPatient = new Patient();
  22.        
  23.         //Variables
  24.         int att = 3;
  25.         int attLeft = 3;
  26.         String inputU;
  27.         String inputPw;    
  28.         boolean login = false;
  29.         //Create Scanner
  30.         Scanner input = new Scanner(System.in);    
  31.        
  32.        
  33.         for(int i = 0; i < att; i++)
  34.         {
  35.             System.out.println("Enter Username: ");
  36.             inputU = input.next();
  37.             System.out.println("Enter Password: ");
  38.             inputPw = input.next();
  39.            
  40.             if(inputU.equals(myPatient.createUserName()) && inputPw.equals(myPatient.createPassword()))
  41.             {
  42.                 System.out.println("Login successful!");
  43.                 login = true;
  44.                 break;
  45.             }          
  46.             else
  47.             {
  48.                 attLeft -= 1;                  
  49.                
  50.                 if(attLeft == 0)
  51.                 {
  52.                     System.out.println("No more login-attempts - Please contact a systemadministrator");
  53.                 }
  54.                 else
  55.                 {
  56.                     System.out.println("Invalid login! - you have " + attLeft + " login-attempts left.");
  57.                 }              
  58.             }      
  59.         }
  60.        
  61.        
  62.         return login;
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement