Package Torello.Java

Class Q


  • public class Q
    extends java.lang.Object
    The class 'Q' (Query) is an extremely simple debugging tool that is similar to an IDE's 'breakpoint' feature, but instead using terminal input.

    The letter Q refers to Questions - as in Shell input questions. The intention is to add a few "pre-written" yes/no or accept/reject methods, just like some of the provided Window-Event Questions in JavaScript.


Stateless Class: This class neither contains any program-state, nor can it be instantiated. The @StaticFunctional Annotation may also be called 'The Spaghetti Report'. Static-Functional classes are, essentially, C-Styled Files, without any constructors or non-static member field. It is very similar to the Java-Bean @Stateless Annotation.
  • 1 Constructor(s), 1 declared private, zero-argument constructor
  • 5 Method(s), 5 declared static
  • 0 Field(s)


    • Method Summary

       
      Program Execution Break Point, Query the User
      Modifier and Type Method
      static void BP()
      static void BP​(String message)
       
      Query a User (at the terminal) a Yes / No Answer
      Modifier and Type Method
      static boolean YN​(String yesOrNoQuestion)
       
      Query a User (at the terminal) an Integer
      Modifier and Type Method
      static int intNUM()
       
      Quick Scanner String Read-Line
      Modifier and Type Method
      static String readLine()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • BP

        🡇    
        public static void BP()
        BP: Break Point

        Asks the user at the Command Line if Program Flow should continue. If the user responds with 'no', then program execution is halted.
        Code:
        Exact Method Body:
         if (! YN("Continue ?")) System.exit(1);
        
      • BP

        🡅  🡇    
        public static void BP​(java.lang.String message)
        BP: Break Point

        Asks the user at the Command Line if Program Flow should continue. If the user responds with 'no', then program execution is halted.
        Parameters:
        message - This is printed to terminal using System.out.println(message) before asking the user if he would like to continue.
        Code:
        Exact Method Body:
         System.out.println(message);
        
         if (! YN("Continue ?")) System.exit(1);
        
      • YN

        🡅  🡇    
        public static boolean YN​(java.lang.String yesOrNoQuestion)
        java.util.Scanner is not the most memorable class, but still, pretty useful. This static method will repeatedly prompt the user using System.out until a 'y' or an 'n' has been pressed.
        Parameters:
        yesOrNoQuestion - This is output to the prompt each time the user fails to enter 'y' or 'n'.
        Returns:
        TRUE if the user pushed 'y' on a single input line, and FALSE if the user has pushed 'n' on a single input line. The question asked will be repeated if neither of those has occurred.
        Code:
        Exact Method Body:
         Scanner input = new Scanner(System.in);
        
         while (true)
         {
             System.out.println(yesOrNoQuestion);
             System.out.println("Please type the letter 'y' or the letter 'n' and [ENTER]");
        
             String yesOrNo = input.nextLine().toLowerCase();
        
             if (yesOrNo.equals("y")) return true;
             if (yesOrNo.equals("n")) return false;
         }
        
      • intNUM

        🡅  🡇    
        public static int intNUM()
        This will query a user for a valid input integer. If the user fails to enter a valid integer, and the Integer.parseInt(user-input); throws an exception, the method will ask the user repeatedly until a valid integer has been provided.
        Returns:
        The integer version of the user's input.
        Code:
        Exact Method Body:
         Scanner input = new Scanner(System.in);
        
         while (true)
         {
             System.out.println("Please enter any valid integer, and then press [ENTER]");
        
             String s = input.nextLine();
        
             try
                 { int n = Integer.parseInt(s); return n; }
             catch (Exception e)
                 { System.out.println("That was not a valid integer, try again."); }
         }
        
      • readLine

        🡅    
        public static java.lang.String readLine()
        Reads a single line of user input, and returns that line as a string.
        Returns:
        return (new Scanner(System.in)).nextLine();
        Code:
        Exact Method Body:
         return (new Scanner(System.in)).nextLine();