Car Rental Problem

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:

Yes. It is always good to test programs with values that are right at the limit.

Car Rental Problem

A car rental agency wants a program to determine who can rent a car. The rules are:

  • A renter must be 21 years old or older.
  • A renter must have a credit card with $10,000 or more of credit.

The program looks something like the cookie program:

// Rental Car Checker
//
import java.util.Scanner;
class RenterChecker
{
  public static void main (String[] args) 
  { 
    // Declare a Scanner and two integer variables
    Scanner scan = new Scanner( System.in ); 
    int age, credit; 

    // get the age of the renter
    System.out.println("How old are you?");
    age = scan.nextInt() ; 

    // get the credit line
    System.out.println("How much credit do you have?");
    credit = scan.nextInt() ; 

    // check that both qualifications are met
    if (  && )
      System.out.println("Enough to rent this car!" );
    else
      System.out.println("Have you considered a bicycle?" );
  }
}

QUESTION 7:

Complete the program by filling in the blanks.