/*
 *  ==========================================================================
 *  TruthTable.java: Create and print a truth table for combination of most
 *  commonly used logical operators:
 * 
 *  -- Part 1: Create a truth table for two propositions. Exercise the
 *             conditional AND operator (i.e.,  &&) and the conditional OR
 *             operator (i.e., ||).
 *  -- Part 2: Exercise the logical negation operator (i.e., !)
 * 
 *  Written by: Mark Austin                                           May 2009 
 *  ==========================================================================
 */

public class TruthTable {
   public static void main( String[] args ) {
      boolean p, q;

      // Part 1: Exercise the conditional operators AND and OR .....

      System.out.println( "Part 1: Exercise conditional AND and OR operators");
      System.out.println( "=========================================");
      System.out.println( "       p        q     (p ^ q)     (p v q)" );
      System.out.println( "=========================================");

      p =  true; q = true;
      System.out.printf(  "%8s %8s %11s %11s\n", p, q, p && q, p || q );
      p = false; q = true;
      System.out.printf(  "%8s %8s %11s %11s\n", p, q, p && q, p || q );
      p =  true; q = false;
      System.out.printf(  "%8s %8s %11s %11s\n", p, q, p && q, p || q );
      p = false; q = false;
      System.out.printf(  "%8s %8s %11s %11s\n", p, q, p && q, p || q );

      System.out.println( "==========================================");

      // Part 2: the conditional OR operator (i.e., ||)

      System.out.println( "");
      System.out.println( "Part 2: Exercise logical negation operator");
      System.out.println( "=========================================");
      System.out.println( "       p       !p                        " );
      System.out.println( "=========================================");

      p = true; 
      System.out.printf(  "%8s %8s \n", p, !p );
      p = false; 
      System.out.printf(  "%8s %8s \n", p, !p );

      System.out.println( "=========================================");

   } 
} 
