Range Testing

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

A 30 year old with $10000 credit could rent a car.

age >= 21 && credit >= 10000
---------    ---------------
  true            true
    ----------------
          true

Range Testing

A welter weight boxer must weight between 136 and 147 pounds. A boxer's weight is tested before each fight to be sure that he is within his weight category. Here is a program that checks if a welter weight boxer's weight is within range:

// Ringside Weigh-in
//
// Boxer must weigh between 136 and 147 pounds
//
import java.util.Scanner;

class Ringside
{
  public static void main (String[] args)  
  { 
    Scanner scan = new Scanner( System.in );
    int weight; 

    // get the weight
    System.out.print("How heavy is the boxer? ");
    weight = scan.nextInt();

    // check that the weight is within range
    if (  )
      System.out.println("In range!" );
    else
      System.out.println("Out of range." );
  }
}

QUESTION 9:

Fill the blank so that weight is tested in two ways:

  • weight must be equal or greater than 136
  • weight must be less than or equal to 147