package rectangle;
import java.util.Scanner;
import java.io.*;
import java.util.*;
// this class is the test program. It will ask the user for the number of rectangles and for the bottom-left corner
// coordinate and the width and height and will output the area, all the pairs of rectangles that overlap each other,
// and also the lower-left corner postion and the dimensions of the rectangle formed by the intersection of each such pair
// and also, it will output, by output I mean print out, the total number of overlaps, the position and dimensions of the rectangle that
// will hold all of the other rectangles.
/**
* @author Paul
*
*/
public class TestRectangleProgram {
/**
* @param args
*/
static Scanner console = new Scanner(System.in);
public static void main(String[] args) {
// TODO Auto-generated method stub
// prints Enter the number of rectangles.
// creates int variable numOfOverlaps and initializes it to 0.
int numOfOverlaps = 0;
System.out.println("Enter the number of rectangles.");
// each array stores a value, xValue, yValue, widthArray, and heightArray.
// The array values, made by the user inputs in the for loop,
// will be called by another for loop that will print out
// xCords[0], yCords[0], widthArray[0], heightArray[0] + add a line
// xCords[1], yCords[1], widthArray[1], heightArray[1] and so on
// for the widthArray and heightArray, their values will be made to fill
// areaArray like this in the for loop: areaArray[j] = rect[j].area() ,
// where rect is an array of Rectangles the size of the number of rectangles.
// user input for # of rectangles
int numOfRectangles;
numOfRectangles = console.nextInt();
// array of x values that will get filled in by the for loop. The array size is the number of rectangles.
double[] xCords = new double[numOfRectangles];
// array of y values that will get filled in by the for loop. The array size is the number of rectangles.
double[] yCords = new double[numOfRectangles];
// array for the width that will get filled in by the for loop. The array size is the number of rectangles
double[] widthArray = new double[numOfRectangles];
// array for the height that will get filled in by the for loop. The array size is the number of rectangles
double[] heightArray = new double[numOfRectangles];
// array to store areas. Array size is the number of rectangles.
double[] areaArray = new double [numOfRectangles];
// for loop will ask user for x-coordinate of rectangle, y-coordinate of rectangle, height of rectangle, and width of rectangle
// until it has done so for the number of rectangles. j is set to 0 and will increase until the for loop exits when the
// value of j reaches the number of rectangles.
Rectangle[] rect = new Rectangle[numOfRectangles];
for (int j = 0; j < numOfRectangles; j++)
{
System.out.println("Enter the x-coordinate for Rectangle " + (j+1)+ " ");
xCords[j] = console.nextDouble();
System.out.println("Enter the y-coordinate for the Rectangle " + (j+1) + " ");
yCords[j] = console.nextDouble();
System.out.println("Enter the width for the Rectangle " + (j+1) + " ");
widthArray[j] = console.nextDouble();
System.out.println("Enter the height for the Rectangle " + (j+1) + " ");
heightArray[j] = console.nextDouble();
rect[j] = new Rectangle(xCords[j], yCords[j], widthArray[j], heightArray[j]);
areaArray[j] = rect[j].area();
System.out.println("Rectangle " + (j+1) + ": " + rect[j].toString());
}
for (int k = 0; k < numOfRectangles; k++)
{
System.out.println("The area of Rectangle " + (k+1) + " is " + areaArray[k] + ".");
}
for(int v = 0; v < numOfRectangles; v++)
{// beginning of for
for (int w = v + 1; w < numOfRectangles; w++)
{ // beginning of inner for
if (rect[v].overlaps(rect[w]) == true)
{ // beginning of if
numOfOverlaps = numOfOverlaps + 1;
} // end of if
} // end of inner for
} // end of for
System.out.println("The number of overlaps is: " + numOfOverlaps);
for (int p = 0; p < numOfRectangles; p++)
{
}
}
}