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



public class Shapes
{
    // instance variables - encode persistant class state, ...more later...
    int width = 0;
    int length = 0;
    String symbol = "@";

    /**
     * Constructor for objects of class Shapes
     */
    public Shapes(int w, int l, String s)
    {
        // initialize instance variables, ...more later...
        width = w;
        length = l;
        symbol = s;
    }

    /**
     * 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() {
        for (int i = 0; i < length; i++){
            for (int j = 0; j < width; j++) {
                System.out.print(symbol);
            }
            System.out.println();
        }
    }
    
    public void printRightTriangle () {
        for (int i = 0; i < width; i++) {
            for (int j = 0; j < i + 1; j++) {
                System.out.print(symbol);
            }
            System.out.println();
        }

    }
    
    public void setWidth(int newWidth) {
        width = newWidth;
    }
    
    public int getWidth() {
        return width;
    }
    
    /**
     *  Reads in a postive 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 shape1 = new Shapes(5, 8, "*");
       Shapes shape2 = new Shapes(6, 4, "a");
       
       // 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();
       shape1.printRectangle();
       shape2.printRectangle();
       shape1.setWidth(shape2.getWidth());
       shape1.printRectangle();
//       int side = manyShapes.getPositiveInt(stdin, "side of a right triangle");
//       manyShapes.printRightTriangle(side, "$");


    }
}
