// Arup Guha
// 3/3/2026
// Test Code for Shape2D interface.
/*** Edited in class on 10/12/2026 to use a ColorRectangle object. ***/

public class TestShape2D {

	public static void main(String[] args) {
	
		// Create some shapes.
		Shape2D[] shapes = new Shape2D[5];
		
		// Perimeter = 10pi, Area = 25pi
		shapes[0] = new Circle(5);
		
		// Perimeter = 12, Area = 6
		shapes[1] = new Triangle(3, 4, 90);
		
		// Perimeter = 24, Area = 16sqrt(3)
		shapes[2] = new Triangle(8, 8, 60);
		
		// Perimeter = 28, Area = 45
		shapes[3] = new Rectangle(5, 9);
		
		// Perimeter = 18, Area = 14
		shapes[4] = new ColorRectangle(7, 2, "Green");
		
		// See what they look like at first.
		for (Shape2D x: shapes)
			System.out.println(x);
		System.out.println("\n--------------------------------\n");
		
		// Just a random test of the methods below.
		// Do the math by hand (and calculator) to get that 
		double ans = cost(shapes, 2, 3);
		System.out.println("Cost of these shapes is "+ans);
		System.out.println("\n--------------------------------\n");
		
		// Now let's try scale factor!
		for (int i=0; i<5; i++)
			shapes[i].scaleBy(i+2);
		
		// Now, we should see everything scaled up!
		for (Shape2D x: shapes)
			System.out.println(x+" P = "+x.getPerimeter()+" "+x.getArea());
		System.out.println("\n--------------------------------\n");
		
		// Testing my rotate method!
		for (int i=0; i<5; i++)
			if (shapes[i] instanceof Rectangle)
				((Rectangle)shapes[i]).rotate();
			
		// Print to just make sure it worked.
		for (Shape2D x: shapes)
			System.out.println(x+" P = "+x.getPerimeter()+" "+x.getArea());
	}
	
	// This method returns the sum of the perimeters of all of the shapes in shapes.
	public static double sumPerimeter(Shape2D[] shapes) {
		double res = 0;
		for (Shape2D x: shapes)
			res += x.getPerimeter();
		return res;
	}
	
	// Does the same for areas of the figures in shapes.
	public static double sumArea(Shape2D[] shapes) {
		double res = 0;
		for (Shape2D x: shapes)
			res += x.getArea();
		return res;
	}
	
	// Returns the total cost for all of this land area. If the cost of the fence per unit
	// is costPerLength and the cost per square unit is costPerArea.
	public static double cost(Shape2D[] shapes, double costPerLength, double costPerArea) {
		return sumPerimeter(shapes)*costPerLength + sumArea(shapes)*costPerArea;
	}
}