// Miya Natsuhara // 07-17-2019 // CSE142 // TA: Grace Hopper // A short program that simulates a login system. import java.util.*; public class LoginSystem { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("What is your name? "); String myName = console.nextLine(); int spaceIndex = myName.indexOf(" "); String firstName = myName.substring(0, spaceIndex); System.out.println("Hello, " + firstName); String realPassword = "password"; System.out.print("Please enter your password: "); String userPassword = console.nextLine(); // NOTE: We *must* use the .equals() method here to compare Strings to see if they are // equivalent (contain the same characters in precisely the same order). // In general, when testing objects for equivalence, we should use the .equals() method // not the == operator (which works as expected for *primitive* types). if (realPassword.equals(userPassword)) { System.out.println("Welcome back!"); } else { System.out.println("take a hike!"); } } }