Suppose you are writing a program that asks the user to give a yes-or-no response. Assume that the program reads the user’s response into the String variable response.

a. If response is yes or y, set the boolean variable accept to true otherwise set it to false.
b. How would you change the code so that it will also accept Yes and Y?


a) ```
if( response.equals("y") || response.equals("yes"))
accept = true;
else
accept = false;
```

b) we can add in extra cases:
```
if( response.equals("y") || response.equals("yes") ||
response.equals("Y") || response.equals("Yes"))
accept = true;
else
accept = false;
```
or modify reponse before the if statement.
```
response = response.toLower();
if( response.equals("y") || response.equals("yes"))
accept = true;
else
accept = false;
```

This code is in Fragments.java.

Computer Science & Information Technology

You might also like to view...

A ________ character represents a parameter that is not yet determined in a SQL ¬statement.

a) exclamation mark (!) b) at (@) c) question mark (?) d) asterisk (*) e) dollar sign ($)

Computer Science & Information Technology

The flowchart shape for a binary decision is a(n) ________

Fill in the blank(s) with correct word

Computer Science & Information Technology

What are the key differences between adjusting images in Expert mode, Quick edit

mode and Guided edit mode? What will be an ideal response?

Computer Science & Information Technology

In the accompanying figure, item 3 points to the ____.

A. Aspect theme B. Dialog Box Launcher C. Mouse pointer D. Ribbon

Computer Science & Information Technology