import java.util.Scanner;

/**********************************************************************
 * Class purpose: Produce Star patterns demonstrating nested loops
 * 
 * @author  Lewis and Loftus, Nancy & Arch Harris (V2), your name (V3)
 * @version V5 10/31/14
 *********************************************************************/
public class StarsSol
{

   /******************************************************************
    * Method purpose:  Prints star patterns. 
    *
    * @param args Command line arguments, ignored
    *****************************************************************/
   public static void main (String[] args)
   {
      int      maxRows;    // maximum number of rows to print
      int      starCnt;    // Stars per row
      int      blnkCnt;    // Blanks preceding the stars

      Scanner  stdIn;      // standard input

      stdIn = new Scanner(System.in);
 
      System.out.print("Enter a positive number for the number of rows: ");
      maxRows = stdIn.nextInt();

      while (maxRows <= 0)
      {
         System.out.printf("\nYou did not enter a POSITIVE number.  You entered %d!\n", maxRows);  
         System.out.print("Enter a positive number for the number of rows: ");
         maxRows = stdIn.nextInt();
      }
      
      //**************************************************
      // First Example, stars per row goes from 1 to maxRow
      //**************************************************
      System.out.println();
      System.out.println("Class example\n");
      for (int row = 1; row <= maxRows; row++)
      {
         starCnt = row;
         for (int star = 1; star <= starCnt; star++) 
         {
            System.out.print ("*");
         }
         System.out.println();
      }
      
      //*******************************************************
      // Insert code for patterns (A), (B), (C), and (D) below.
      //*******************************************************
      System.out.println("\nPattern A\n");
      for (int row = 0; row < maxRows; row++)
      {
         starCnt = maxRows - row;
         for (int star = 1; star <= starCnt; star++) 
         {
            System.out.print ("*");
         }
         System.out.println();
      }

      System.out.println("\nPattern B\n");
      for (int row = 1; row <= maxRows; row++)
      {
         starCnt = row;
         blnkCnt = maxRows - row;
         
         for (int blnk = 1; blnk <= blnkCnt; blnk++) 
         {
            System.out.print (" ");
         }
         for (int star = 1; star <= starCnt; star++) 
         {
            System.out.print ("*");
         }
         System.out.println();
      }

      System.out.println("\nPattern C\n");
      for (int row = 0; row < maxRows; row++)
      {
         starCnt = maxRows - row;
         blnkCnt = row;
         
         for (int blnk = 1; blnk <= blnkCnt; blnk++) 
         {
            System.out.print (" ");
         }
         for (int star = 1; star <= starCnt; star++) 
         {
            System.out.print ("*");
         }
         System.out.println();
      }

      /* there are a couple of ways of approaching this problem.
       * You could divide the thing in half and do one half then 
       * the other. Or you could just decide where you are in the pattern 
       * and increment or decrement accordingly.
       */
      System.out.println("\nPattern D\n");
      
      starCnt = 1;
     
      // blnk Cnt is different for even or odd
      // maxRows. We need one extra for odd # rows.
      blnkCnt = (maxRows - 1) / 2 + (maxRows % 2);
      
      for (int row = 1; row <= maxRows; row++)
      {   
         for (int blnk = 1; blnk <= blnkCnt; blnk++) 
         {
            System.out.print (" ");
         }
         for (int star = 1; star <= starCnt; star++) 
         {
            System.out.print ("*");
         }
         
         if (row < maxRows / 2)
         {
            starCnt = starCnt + 2;
            blnkCnt--;
         }
         else
         {
            if (row > maxRows / 2)
            {
               starCnt = starCnt - 2;
               blnkCnt++;
            }
            else if (maxRows % 2 == 1)   
            {
               starCnt = starCnt + 2;
               blnkCnt--;
            }
            // else if (maxRows % 2 == 0) // even number, do nothing
         }   
         
         System.out.println();
      }

   
   }
}
