Hands on Testing Java: Lab #7

Prelab Questions

Type in your answers to each of these questions in a file named prelab07.txt in your Prelab Questions directory. Turn in your answers before the beginning of your laboratory session.

Short Answer Questions

Question #1: What are the six relational operators?

Question #2: What are the three logical operators?

Question #3: Name one of the Java statements that provide for selective behavior.

Question #4: Name the other Java statement that provides for selective behavior.

Question #5: What types of data can be used in a switch statement?

Suggestion: Look at the code for the test methods in the CalculatorTest class and figure out the expected values.

Programming Questions

Make sure you make a distinction between "expressions" and "statements" when answering the following questions. (Look at the introduction for Lab #3 is the difference isn't clear.)

Code #1: Write an expression that tests if x is less than 25.0.

Code #2: Write an expression that tests if x is between 25.0 and 50.0, inclusive. (Reminder: this requires two separate comparisons joined with a Boolean operator.)

Code #3: Write an if statement that prints "Hello" if x is less than 25.0.

Code #4: Write an if statement that prints "Hello" if x is less than 25.0, "Whatever" if x is between 25.0 and 50.0 (inclusive), and "Goodbye" if x is greater than 50.0. (Hint: this multi-branch if requires only two tests.)

Code #5: What can't a switch statement be used for the selection done in the previous questions? Give two reasons.