// Yazzy Latif // 07/17/2020 // 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(); // something with index of --> spaceIndex int spaceIndex = myName.indexOf(" "); // something with substring --> chop up string String firstName = myName.substring(0, spaceIndex); System.out.println("Hello, " + firstName); String realPassword = "password"; System.out.print("Enter your password please: "); 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, here are some cookies"); } else { System.out.println("Take a hike"); } } }