Assignemnt #51: Comparing Last Names
Code
/// Name: Sean Harrison
/// Period: 7
/// Program name: Alphabetical Orders
/// File Name: AlphabeticalOrder.java
/// Date Finished: 11/3/2015
import java.util.Scanner;
public class AlphabeticalOrder
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
String lastName;
int a, b, c, d;
a = 0;
b = 0;
c = 0;
d = 0;
System.out.println( "What's your last name? " );
lastName = keyboard.next();
a = lastName.compareTo("Carsell");
if ( a <= 0 )
{
System.out.println( "you don't have to wait long, " + lastName + "." );
}
else if ( a > 0)
{
b = lastName.compareTo("Jones");
if ( b <= 0 )
{
System.out.println( "Thats not bad, " + lastName + ".");
}
else if (b > 0 )
{
c = lastName.compareTo("Smith");
if ( c <= 0)
{
System.out.println( "Looks like a bit of a wait " + lastName + "." );
}
else if ( c > 0)
{
d = lastName.compareTo("Young");
if ( d <= 0)
{
System.out.println( "It's going to be a while " + lastName + ".");
}
else if ( d > 0)
{
{
System.out.println( "I hope you're not going anywhere for a while " + lastName + "." );
}
}
}
}
}
}
}
Picture of the output