// Arup Guha
// 2/12/10
// Solution to 2D Array Quiz Program Problem

import java.util.*;

// This class manages a basic point.
class point {
	
	public int x;
	public int y;
	
	public point(int myx, int myy) {
		x=myx;
		y=myy;
	}
}

public class grid {
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		char[][] board = new char[10][10];
		
		// This is the beginning board.
		fill(board, new point(0,0), new point(9,9), '-');
		
		print(board);
		System.out.println("Would you like to add a rectangle(yes,no)");
		String answer = stdin.next();
		
		// Keep on going as long as the user wants to.
		while (answer.toLowerCase().equals("yes")) {

			// Get all relevant coordinates.
			System.out.println("What are the coordinates of the top left square(0-9,0-9)?");
			int x1 = stdin.nextInt();
			int y1 = stdin.nextInt();
			System.out.println("What are the coordinates of the bottom right square(0-9,0-9)?");
			int x2 = stdin.nextInt();
			int y2 = stdin.nextInt();

			// And the character.
			System.out.println("What character do you want to fill the rectangle?");
			String myChar = stdin.next();

			// Fill and print!
			fill(board, new point(x1,y1), new point(x2,y2), myChar.charAt(0));
			print(board);
			System.out.println("Would you like to add a rectangle(yes,no)");
			answer = stdin.next();
		}
		
	}
	
	// This method just prints out a 2D array of chars.
	public static void print(char[][] board) {
		
		System.out.println("Here is your grid:\n");
		for (int i=0; i<board.length; i++) {
			for (int j=0; j<board[i].length; j++)
				System.out.print(board[i][j]+" ");
			System.out.println();
		}
	}
	
	// This method fills board, from the point topleft to
	// the point bottom right with the character c.
	public static void fill(char[][] board, point topleft, point botright, char c) {

		// Make sure both loop bounds are inclusive.
		for (int i=topleft.x; i<=botright.x; i++)
			for (int j=topleft.y; j<=botright.y; j++) {
				board[i][j] = c; // Fills with c.
			}
	}
}
