Part 1: Writing Exercise:

The following are the exercises about the expression/condition in Java.

  • Write an expression to check whether an integer variable named num is odd.
  • Write an expression to check whether a double-type variable named total is between 97 and 100.
  • Write an expression to check whether a String variable named str is equal to "ASU".
  • Consider the following code snippet. if (!(!(a == 1) && (b == 0))) System.out.println("TRUE"); Describe what the values for a and b must be for the program to output "TRUE". In other words, list up all cases when the expression will be true such as (a, b) = (0, 0), (1, 0), etc. Assume that a and b can be either 0 or 1.
  • Assume you have two numbers, x and y (they can be take any values, positive as well as negative). Write an expression that return true if and only if one of the numbers is odd and the other even.

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) …

*/

Part 2: Programming

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.

Example Execution:

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 ***
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.