Alphabetical Order
Code
/// Name: Rachel Smith
/// Period: 5
/// Program Name: Alphabetical Order
/// File Name: AlphabeticalOrder.java
/// Date Finished: 11/6/2015
import java.util.Scanner;
public class AlphabeticalOrder {
public static void main( String[] args ) {
Scanner keyboard = new Scanner(System.in);
String name;
System.out.print( "What's your last name? " );
name = keyboard.next();
int a = name.compareTo("Carswell");
int b = name.compareTo("Jones");
int c = name.compareTo("Smith");
int d = name.compareTo("Young");
if ( a <= 0 ) {
System.out.println( "You don't have to wait long." );
}
else if ( b <= 0 ) {
System.out.println( "That's not bad." );
}
else if ( c <= 0 ) {
System.out.println( "Looks like a bit of a wait." );
}
else if ( d <= 0 ) {
System.out.println( "It's gonna be a while." );
}
else {
System.out.println( "I hope you're not going anywhere for a while." );
}
}
}
Picture of the output