Open a JOptionPane confirm dialog as shown on Figure 1 below. This dialog box is a graphical embodiment of the if-else logic. However, the button clicks of this window return integer values, not a boolean value or String. Follow the template exactly. The syntax is similar to that of the other dialogs:
JOptionPane.showConfirmDialog(null, , , JOptionPane.YES_NO_OPTION);
Note that a button click makes this method return an integer number which is one of the two named constants
JOptionPane.YES_OPTION or JOptionPane.NO_OPTION
Assign the return value to an integer variable like
int choice = JOptionPane.showConfirmDialog(null,etc)
(1pt) Using an if statement like
if(choice == JOptionPane.NO_OPTION)
you check if choice is the No option, in that case send the message
The program terminates!
to the console and terminate the program with the System.exit(0) statement.
Otherwise do as follows:
Solicit three names written in a row to a JOptionPane input window as shown in
Figure 2. Each name must be one word and the words are separated by spaces. Follow the template layout accurately, but you can choose other names. Save the return value in a variable named names. Remember, the input window returns a string.
Validate the input: null string or empty string is not accepted for names. Use the same if logic as in Lab 4, in the if block print the message
"Input is not valid, program terminates"
to the console and terminate the program.
Otherwise do as follows to learn a new Scanner property:
Declare three String variables name1, name2 and name3 to serve as the storage for the individual names from the input
Declare and instantiate a Scanner reference splitter as in your previous assignments, but this time write in the constructor for parameter the variable names (rather than System.in). Here is the code for the instantiation (do not forget to import the util package above the class header):
Scanner splitter = new Scanner(names);
Apply the method call splitter.next( ) three times and save the return values one after each other in the variables name1,name2 and name3, respectively
Create an if-else logic to determine the lexicographic order of the names. This logic is supposed to be the same as the one you implemented in the incomplete version.
For this purpose use the compareTo method of the String class with the 'ignore case' option (see the book p 150); declare and use additional helper variables if needed. There are six possible orders for three names, your selection logic must cover all six of of them.
If you did Lab 5 Incomplete, you can use your code solving the book Programming Challenge 7.
(1pt) Collect and save the names in correct order in a single String variable namesOrdered
(1pt) Display the variable namesOrdered on a message dialog.
(1pts) Test your program for each of the 6 possible arrangements of three input words (you may use short words for testing purposes like "Abe" "Bo" "Cy".