Boolean Expressions

This chapter introduces relational and logical operators. It also discusses the use of these operators to write Boolean expressions.

20. Insulated Wall Problem


The program runs. However, it is not clear what negative values mean in this situation. The program could be improved by
calling the user's attention to possibly erroneous data.

Insulated Wall Problem

To meet building code requirements, outside walls of new houses must be well insulated. Say that the building code requires outside walls to be insulated with at least 4 inches of fiberglass batting or with at least 3 inches of foam insulation.

Here is a program that asks for the number of inches of fiberglass and the number of inches of foam and determines if a new house meets the building code.

import java.util.Scanner;
public class HotHouse
  public static void main (String[] args) 
    Scanner scan = new Scanner( ); 
    int fiber, foam ; 

    // get the inches of fiber
    System.out.println("How much fiber?");
    fiber = scan.nextInt() ;  

    // get the inches of foam
    System.out.println("How much foam?");
    foam  = scan.nextInt() ;  

    // check that at least one requirement is met
    if (  ||  )
      System.out.println("House passes the code requirements!" );
      System.out.println("House fails." );


Question 20:

Fill in the blanks so that the program works correctly.