Assignment #51: Alphabetical Order
Code
/// Name: Kiran O'Farrell
/// Program Name: AlphabeticalOrder
/// File Name: AlphabeticalOrder.java
/// Date completed: 11/28/15
import java.util.Scanner;
public class AlphabeticalOrder {
public static void main (String[] args) {
Scanner keyboard = new Scanner(System.in);
String lastName;
System.out.println("What's your last name?");
lastName = keyboard.next();
if (lastName.compareTo("Carswell") < 0) {
System.out.println("You don't have to wait long.");
}
else if (lastName.compareTo("Carswell") >= 0 && lastName.compareTo("Jones") < 0) {
System.out.println("That's not too bad.");
}
else if (lastName.compareTo("Jones") >= 0 && lastName.compareTo("Smith") < 0) {
System.out.println("Looks like a bit of a wait.");
}
else if (lastName.compareTo("Smith") >= 0 && lastName.compareTo("Young") < 0) {
System.out.println("It might be a while.");
}
else if ((lastName.compareTo("Young")) >= 0) {
System.out.println("Hope you're not going anywhere.");
}
}
}
Picture of the output