Problem 39

Alphabetical Order

Make a program that asks for the last name of the user. Depending on their last name, make a statement about how long they have to wait during roll call. You need to use else ifs to make sure only one statement gets printed.

Once you understand how compareTo() works, this is a pretty straightforward assignment, much like How Old Are You, specifically, except that it uses Strings instead of ints and so you must use the compareTo() method.

name is "Carswell" or before: say "you don't have to wait long"
name is "Jones" or before: say "that's not bad"
name is "Smith" or before: say "looks like a bit of a wait"
name is "Young" or before: say "it's gonna be a while"
name is after "Young": say "not going anywhere for a while?"
What's your last name? Stephanopolis
It's going to be a while before we get to you, "Stephanopolis".

◄ 38: compareTo() Challenge 40: The Worst Number-Guessing Game Ever ►



Adapted from ProgrammingByDoing.com
©2013 Graham Mitchell

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.