# CSE 110 – Assignment #3

\$30.00

## Description

Part 1: Writing Exercise: (5 pts)
The following code is to read three integers and display them from the smallest to the largest. It
creates six integer variables. The a, b, and c are used for the first, second, and third user
inputs. The small, middle, and large are used to display the values from a, b, c
corresponding to the order of values. Write the code and test it. If it works, then answer each
question below.
a. This program is not completed yet. We need to test six cases to figure out what is
wrong. For the case of 1, 2, and 3 inputs, we need to test the 6 cases of
(first, second, third) = (1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), and (3, 2, 1).
Test all of them and write the input and output of wrong case(s), and explain the reason
b. In the line 23 (the line numbers are shown in the left of code), write a single statement
to complete the program. (1pt).
c. The code is to compare three numbers.
Suppose to develop another program to compare three string data. When you check the
alphabet order of string data instead of numbers, it is required to use
compareTo(String) method. For example, if you want to compare
str1=”Yoshi” and str2=”Mario”, use
if(str1.compareTo(str2) > 0)
Read the textbook (Special Topic 3.2) and answer whether the if-statement above is
evaluated as true or false, and explain the reason in your words. (1 pt).
d. Answer the result of the statement, and explain the reason. (1 pt).
“Yoshi”.compareTo(“yoshi”)
e. All characters are ordered in Java. The alphabet letters are ordered as “A”, “B”, “C”…
“Z”, “a”, “b”…. “y”, “z”. In other words, if a capitalized letter is not between “A” and
“Z”, the letter must not be an alphabet such as a special symbol or number. Make the ifstatement to check if a string variable (supposed to be a single letter), str, is an
alphabet letter or not. (1 pt).
if (str.toUpperCase().compareTo(???) >=0 &&
str.toUpperCase().compareTo(???) <= 0) 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) For Input (X, X, X), it returns a wrong output as (X, X, X), because … b) xxx = xxxx; c) XXX because … d) XXX because … e) XXX and XXX */ © 2018 Yoshihiro Kobayashi
Part 2: Programming (15 pts)
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.
*) Part1 is a big hint for this part.
1. 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”.
2. The first letter of output (displayed) name should be capitalized and the others are lower
cases (5 pts).
3. If the name starts with non-alphabetic letter, then display an error message (5 pts) after
it is input. In the case, use a blank name. Look at the example execution for more
details and the display format.
(*) Use the compareTo(String) method. (Special Topic 3.2 in Textbook)
IMPORTANT on Programming
• It is allowed to make only one Scanner variable. In your PC, it may work with
multiple Scanner variables, but the server site (online submission) does not accept it. If
you make more than one Scanner variables, you may lose all 15 points.
• Use only the Java statements that have been covered in class (or textbook) to date. This
means you CAN use declaration, assignment, input and output statements. DO NOT use
any other statements ( loop, array, break, sort, etc.). If in doubt, ask your TA or instructor.
If you use them, then you lose the points of task.
• Use the next() method instead of nextLine()when you read the String data using
Scanner in this assignment. Your PC can work in either way, but not on the server site.
Example Execution:
The following is an example input and output. The input is shown in red (Not displayed But
typed). Make your own questions rather than this example.
Example 1
Please input the first name: Smith
(Smith) is the name list
Please input the second name: jOHN
(John, Smith) is the name list
Please input the third name: mike
Get input Calculate Display results
(John, Mike, Smith) is the name list.
*** END OF Assignment#3 ***
Example 2
Please input the first name: 007James
Error: The first letter should be an alphabet.
() is the name list
Please input the second name: chris
(Chris) is the name list
Please input the third name: GEORGE
(Chris, George) is the name list
*** END OF Assignment#3 ***
/**********************************************************************************
Submit your homework by following the instructions below:
**********************************************************************************/
• Go to the course web site (my.asu.edu), and then click on the on-line Submission tab. Log in the
site using the account, which was registered at the first Lab session. Make sure you use the correct