Assignment #51 and Alphabetical Order
Code
///Name: Tim Gibson
///Period: 6
///Project Name: Alphabetical Order
///File Name: Alphabetical.java
///Date Finished: 10/13/15
import java.util.Scanner;
public class Alphabetical
{
public static void main ( String[] args )
{
Scanner keyboard = new Scanner(System.in);
String name;
int a, b, c, d;
System.out.print( "What's your last name? " );
name = keyboard.next();
a = name.compareTo("Carswell");
b = name.compareTo("Jones");
c = name.compareTo("Smith");
d = name.compareTo("Young");
if ( a <= 0 )
{
System.out.println( "You don't have to wait long, \"" + name + "\"." );
}
else if ( b<= 0 )
{
System.out.println( "That's not bad, \"" + name + "\".");
}
else if ( c <= 0 )
System.out.println( "Looks like a bit of a wait, \"" + name + "\"." );
else if ( d <= 0 )
System.out.println( "It's gonna be a while, \"" + name + "\"." );
else
System.out.println( "You're not going anywhere for a while, \"" + name + "\"." );
}
}
Picture of the output