Advertisement
Guest User

Untitled

a guest
Mar 14th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. package model;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class LogIn {
  6.     Patient myPatient;
  7.  
  8.     public LogIn(Patient myPatient) {
  9.         this.myPatient = myPatient;
  10.     }
  11.    
  12.     //****1)Create a login method that return true if user can successfully login
  13.     // You will need a loop here and give user 3 chances to log into the system
  14.     public boolean loggedIn() {
  15.        
  16.         Scanner input = new Scanner(System.in); //Create a Scanner object
  17.        
  18.         //Declare variables
  19.         int i = -1;    
  20.         String inputUsername;
  21.         String inputPassword;
  22.         boolean login = false;
  23.        
  24.         //Loop 3 times for the  user to enter right username and password, after 3 fails return value false
  25.         for (i = 0; i < 3; i++) {
  26.             System.out.println("Enter your username: ");
  27.             inputUsername = input.nextLine();
  28.             System.out.println("Enter your password: ");
  29.             inputPassword = input.nextLine();
  30.                
  31.                 //If the user enters correct username and password assign value true to login and break the loop
  32.                 if (inputUsername.equals(myPatient.username) && inputPassword.equals(myPatient.password)) {
  33.                     login = true;
  34.                     break;
  35.                 }
  36.                
  37.                 //If the user enters wrong username or password enter error message and restart the loop
  38.                 else {
  39.                 System.out.println("You pressed wrong password and/or username");
  40.                 }
  41.         }
  42.        
  43.         return login;//****2)Replace the "true" with the result from the code
  44.    
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement