
/**
 * class Shapes prints out square boxes, rectangles, triangles
 * 
 * @author Kathryn
 * @version February 2007
 */
import java.util.*;



public class Shapes
{
    // instance variables - encode persistant class state, ...more later...

    /**
     * Constructor for objects of class Shapes
     */
    public Shapes()
    {
        // initialize instance variables, ...more later...
    }

    /**
     * Print a square box with an "*" symbol
     * 
     * @param side the length of the box
     * 
     * @return nothing void 
     *
     * In class: (1) How do we make a Shape?
     *           (2) How do we tell the printBox method the width?
     *           (3) What if we want the symbol to be a parameter?
     *           (4) Add a method for reading length
     *           (4) Fix the comments to reflect our code
     */           
    public void printBox(int side)
    {
        String s = "*";
        for (int i = 0; i < side; i++) {
            for (int j = 0; j < side; j++) {
                System.out.print(s);
            }
            System.out.println();
        }
    }
    /* printRectangle prints a rectangle with a symbol 
     *   @param width
     *   @param height
     *   @param String s
     */
    public void printRectangle(int width, int height, String s) {
        for (int i = 0; i < height; i++){
            for (int j = 0; j < width; j++) {
                System.out.print(s);
            }
            System.out.println();
        }
    }
    public void printRightTriangle (int side, String s) {
        for (int i = 0; i < side; i++) {
            for (int j = 0; j < i + 1; j++) {
                System.out.print(s);
            }
            System.out.println();
        }
        
    }
    /* Reads in a postiive integer
     * @param systemIn the input console object
     * 
     */
    public int getPositiveInt(Scanner systemIn, String sideName){
       int width = 0;
       boolean badWidth = true;
       
       while (badWidth) {
           // Error checking
           System.out.print("Enter positive integer for " + sideName + ": ");
           if (!systemIn.hasNextInt()) {
               System.out.println("That is not an integer");
               systemIn.next();
           } else {
               width = systemIn.nextInt();
               if (width < 0) {
                    System.out.println("Distances must be positive.");
                }
                else { // width >= 0 and its an integer 
                    badWidth = false;
                    // System.out.println("Your box width is: " + width + ".\n"); 
                }
           }
       }
       return width;
        
    }

    public static void main(String[] args)
     {
       // allocate an object of class Shapes named myshapes
        
       Shapes manyShapes = new Shapes();

       // always allocate a Scanner object for input
       Scanner stdin = new Scanner(System.in);  
       
       int width = manyShapes.getPositiveInt(stdin, "width of a rectangle");
       int height = manyShapes.getPositiveInt(stdin, "height of a rectangle");
       
 //      manyShapes.printBox(width);
       System.out.println();
       manyShapes.printRectangle(width, height, "j");
       
       int side = manyShapes.getPositiveInt(stdin, "side of a right triangle");
       manyShapes.printRightTriangle(side, "$");

    
    }
}
