/*                            The Stars Program
			           Arup Guha
				   2/19/99

Description: The program draws stars in several designs. First a menu is given
             to the user. The user then chooses which design he/she would like
	     to see. After the choice is made, the user is asked how big he/she
	     would like the particular star design. Then the design is printed
	     to the screen and the menu is displayed again.
*/

import java.io.*;

class Stars {

    public static void main(String args[]) throws IOException {

	BufferedReader stdin = new BufferedReader
	    (new InputStreamReader(System.in));
	
	// Main loop. Runs until user quits.
	int choice = 1;
	while (choice !=5) {
	
	    choice = menu(); // Displays menu and retrieve's user's choice.
	    // Calls appropriate method(s) based on user's choice.
	    if (choice == 1) {
		System.out.println("What size do you want your triangle?");
		int side = Integer.parseInt(stdin.readLine());
		Triangle(side);
	    }
	    else if (choice == 2) {
		System.out.println("What size do you want your upside down triangle?");
		int side = Integer.parseInt(stdin.readLine());
		UpsideDownTriangle(side);
	    }
	    else if (choice == 3) {
		System.out.println("What size do you want your pyramid?");
		int side = Integer.parseInt(stdin.readLine());
		Triangle(side);
		UpsideDownTriangle(side-1);
	    }
	    else if (choice == 4) {
		System.out.println("What size do you want your square?");
		int side = Integer.parseInt(stdin.readLine());
		Square(side);
	    }
	}

    }

    // This method prints out the menu to the screen and returns an integer
    // corresponding to their menu choice. Incidentally, the menu choice
    // returned is guaranteed to be in between 1 and 5, inclusive.
    public static int menu() throws IOException {
	
	BufferedReader stdin = new BufferedReader
	    (new InputStreamReader(System.in));
	int choice = 1;
	boolean okay = false;
	while (!okay) {
	    System.out.println("Welcome to Stars-R-Us!!!");
	    System.out.println("Here are your menu options: ");
	    System.out.println("1. Print a triangle");
	    System.out.println("2. Print an upside down triangle");
	    System.out.println("3. Print a pyramid");
	    System.out.println("4. Print a square");
	    System.out.println("5. Quit");
	    choice = Integer.parseInt(stdin.readLine());
	    if (choice >= 1 && choice <=5)
		okay = true;
	    else
		System.out.println("Not a valid menu option. Try again.");
	}
	return choice;
    }

    // Prints a triangle with side length length to the screen.
    public static void Triangle(int length) {

	int linecounter = 1;
	while (linecounter <= length) {
	 
	    int starcounter = 1;
	    while (starcounter <= linecounter) {
		System.out.print("*");
		starcounter++;
	    }
	    
	    System.out.println();
	    linecounter++;
	}
    }

    // Prints an upside down triangle of side length length to the screen
    public static void UpsideDownTriangle(int length) {

	int linecounter = 1;
	while (linecounter <= length) {
	 
	    int starcounter = 0;
	    while (starcounter <= length - linecounter) {
		System.out.print("*");
		starcounter++;
	    }
	    
	    System.out.println();
	    linecounter++;
	}
    }

    // Prints a square with side length length to the screen.
    public static void Square(int length) {

	int linecounter = 1;
	while (linecounter <= length) {

	    int starcounter = 1;
	    while (starcounter <= length ) {
		System.out.print("*");
		starcounter++;
	    }
	    
	    System.out.println();
	    linecounter++;
	}
    }
}

