Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package model;
- import java.util.Scanner;
- public class LogIn {
- Patient myPatient;
- public LogIn(Patient myPatient) {
- this.myPatient = myPatient;
- }
- //****1)Create a login method that return true if user can successfully login
- // You will need a loop here and give user 3 chances to log into the system
- public boolean loggedIn() {
- Scanner input = new Scanner(System.in); //Create a Scanner object
- //Declare variables
- int i = -1;
- String inputUsername;
- String inputPassword;
- boolean login = false;
- //Loop 3 times for the user to enter right username and password, after 3 fails return value false
- for (i = 0; i < 3; i++) {
- System.out.println("Enter your username: ");
- inputUsername = input.nextLine();
- System.out.println("Enter your password: ");
- inputPassword = input.nextLine();
- //If the user enters correct username and password assign value true to login and break the loop
- if (inputUsername.equals(myPatient.username) && inputPassword.equals(myPatient.password)) {
- login = true;
- break;
- }
- //If the user enters wrong username or password enter error message and restart the loop
- else {
- System.out.println("You pressed wrong password and/or username");
- }
- }
- return login;//****2)Replace the "true" with the result from the code
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement