Assignment #51 Alphabetical Order
Code
/// Name: John Huh
/// Period: 6
/// Program Name: Alphabetical Order
/// File Name: AlphabeticalOrder.java
/// Date Finished: 11/4/2015
import java.util.Scanner;
public class AlphabeticalOrder
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
String lastName, c, j, s, y;
int wait1, wait2, wait3, wait4;
c = "Carswell";
j = "Jones";
s = "Smith";
y = "Young";
System.out.println();
System.out.print( "What's your last name? " );
lastName = keyboard.next();
wait1 = ( lastName.compareTo(c) );
wait2 = ( lastName.compareTo(j) );
wait3 = ( lastName.compareTo(s) );
wait4 = ( lastName.compareTo(y) );
if ( wait1 <= 0 )
{
System.out.println( "You don't have to wait long, " + lastName + "." );
}
else if ( wait2 <= 0 )
{
System.out.println( "That's not bad, " + lastName + "." );
}
else if ( wait3 <= 0 )
{
System.out.println( "Looks like a bit of a wait, " + lastName + "." );
}
else if ( wait4 <= 0 )
{
System.out.println( "It's gonna be a while, " + lastName + "." );
}
else if ( wait4 > 0 )
{
System.out.println( "Not going anywhere for a while, " + lastName + "?" );
}
System.out.println();
}
}
Picture of the output