Class Prompt


public class Prompt extends Object
Prompt.java - Uses BufferedReader. Provides utilities for user input. This enhances the BufferedReader class so our programs can recover from "bad" input, and also provides a way to limit numerical input to a range of values. The advantages of BufferedReader are speed, synchronization, and piping data in Linux.
Since:
September 1, 2026
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static char
    Prompts the user for a character and returns the character.
    static double
    Prompts the user for a double and returns the double.
    static double
    getDouble(String ask, double min, double max)
    Prompts the user for a double and returns the double.
    static int
    Prompts the user for an integer and returns the integer.
    static int
    getInt(String ask, int min, int max)
    Prompts the user for an integer using a range of min to max, and returns the integer.
    static String
    Prompts user for string of characters and returns the string.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Prompt

      public Prompt()
  • Method Details

    • getString

      public static String getString(String ask)
      Prompts user for string of characters and returns the string.
      Parameters:
      ask - The prompt line
      Returns:
      The string input
    • getChar

      public static char getChar(String ask)
      Prompts the user for a character and returns the character.
      Parameters:
      ask - The prompt line
      Returns:
      The character input
    • getInt

      public static int getInt(String ask)
      Prompts the user for an integer and returns the integer.
      Parameters:
      ask - The prompt line
      Returns:
      The integer input
    • getInt

      public static int getInt(String ask, int min, int max)
      Prompts the user for an integer using a range of min to max, and returns the integer.
      Parameters:
      ask - The prompt line
      min - The minimum integer accepted
      max - The maximum integer accepted
      Returns:
      The integer input
    • getDouble

      public static double getDouble(String ask)
      Prompts the user for a double and returns the double.
      Parameters:
      ask - The prompt line
      Returns:
      The double input
    • getDouble

      public static double getDouble(String ask, double min, double max)
      Prompts the user for a double and returns the double.
      Parameters:
      ask - The prompt line
      min - The minimum double accepted
      max - The maximum double accepted
      Returns:
      The double input