
/**
 * 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();
        }
    }
    /* Reads in a postiive integer
     * @param systemIn the input console object
     * 
     */
    public int getPositiveInt(Scanner systemIn){
       int width = 0;
       boolean badWidth = true;
       
       while (badWidth) {
           // Error checking
           System.out.print("Enter the width of a box: ");
           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 squareAndre = new Shapes();

       // always allocate a Scanner object for input
       Scanner stdin = new Scanner(System.in);  
       
       int width = squareAndre.getPositiveInt(stdin);
       squareAndre.printBox(width);
    }
}
