The following are the exercises about the expression/condition in Java.
Note: The answers to the 5 questions (a through e) above should be typed in the block of comments in the java file such as;
/*
a) XXX != XXX …
…
d) (a, b) = (XXX, XXX) (XXX, XXX) …
…
*/
Write a Java program called Assignment3.java. The program is to display questions and read user inputs, then calculate and print out the requested value with a proper format. This program will follow a very simple process.
Get input -> Calculate -> Display results
Task: Read three names one by one, and display the list in alphabetic/lexicographic order (5 pts). For example, when the inputs are "Smith", "john", and "mike", it displays "John, Mike, and Smith". The first letter of output (displayed) name is always capital and the others are lower cases (5 pts). If the name starts with non-alphabetic letter, then display an error message (5 pts). Look at the example execution for more details. (*) Use the compareTo(String) method. (page 92)
Use only the Java statements that have been covered in class to date. DO NOT use any other statements (loop, array, break, sort, etc.) or topic. If in doubt, ask your TA or instructor. If you use them, then you lose the points of task.
The following is an example input and output. The input is shown in red. Make your own questions rather than this example.
Example 1
*** TASK: Read names and display them in alphabetic order ***
Please input the first name: Smith
Smith is the first name.
Please input the second name: jOHN
John is the second name.
Please input the third name: mike
Mike is the third name
The names are "John", "Mike", and "Smith".
*** END OF Assignment#3 ***
Example 2
*** TASK: Read names and display them in alphabetic order ***
Please input the first name: 48AKB
Error: The first name was not accepted.
Please input the second name: chris
Chris is the second name.
Please input the third name: GEORGE
George is the third name
The names are "Chris" and "George".
*** END OF Assignment#3 ***