CS 1401 Homework #3

Date Assigned: Monday, September 26, 2005 or Tuesday, September 27, 2005.

Due Date: Wednesday, September 28, 2005, or Thursday, September 29, 2005, before the beginning of your lecture section.

Goal: the goal of this assignment is to learn how to deal with Boolean variables and if-then statements in Java.


Let us assume that we have a variable age of type int, and a variable beer of type String.

1. In each subproblem, write Java statements that assign, to a Boolean variable boolVar, the value "true" or "false" depending on whether the following conditions hold:

(a) age < 21

(b) 18 < age < 21

(c) the variable beer contains the string "non-alcoholic"

(d) the value of the string beer follows "non-alcoholic" in alphabetic order

(e) the age (i.e., the value of the variable age) is smaller than 21, and the name of the beer (i.e., the value of the variable beer) is "non-alcoholic"

2. In El Paso, the legal drinking age is 21; in Ciudad Juarez, it is 18. Write a piece of code that does the following: