ADD file via upload

main
p5wft6kpg 4 months ago
parent 1b8e60047d
commit b00da978ff

@ -0,0 +1,73 @@
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
// Test the shape classes and functionality
List<Shape> shapes = new ArrayList<>();
shapes.add(new Square(5.0, "Red"));
shapes.add(new Circle(3.0, "Blue"));
// Test ColorFilter
ColorFilter redFilter = new ColorFilter("Red");
List<Shape> redShapes = redFilter.filterByColor(shapes);
System.out.println("Number of red shapes: " + redShapes.size());
// Test Resizable functionality
for (Shape shape : shapes) {
if (shape instanceof Resizable) {
System.out.println("Before resize: " + shape.calculateArea());
((Resizable) shape).resize(1.5);
System.out.println("After resize: " + shape.calculateArea());
}
}
// Test ShapeStatisticsAnalyzer
ShapeStatisticsAnalyzer analyzer = new ShapeStatisticsAnalyzer(shapes);
analyzer.printStatistics();
// Test Shape Conversion System
System.out.println("\n===== Testing Shape Conversion =====");
CircleToSquareConverter circleToSquare = new CircleToSquareConverter();
SquareToCircleConverter squareToCircle = new SquareToCircleConverter();
Circle originalCircle = new Circle(4.0, "Green");
Square convertedSquare = circleToSquare.convert(originalCircle);
System.out.println("Original Circle: Area = " + originalCircle.calculateArea() + ", Color = " + originalCircle.getColor());
System.out.println("Converted Square: Area = " + convertedSquare.calculateArea() + ", Color = " + convertedSquare.getColor() + ", Side = " + convertedSquare.getSide());
Square originalSquare = new Square(6.0, "Yellow");
Circle convertedCircle = squareToCircle.convert(originalSquare);
System.out.println("Original Square: Area = " + originalSquare.calculateArea() + ", Color = " + originalSquare.getColor());
System.out.println("Converted Circle: Area = " + convertedCircle.calculateArea() + ", Color = " + convertedCircle.getColor() + ", Radius = " + convertedCircle.getRadius());
// Test Composite Shape System
System.out.println("\n===== Testing Composite Shape =====");
CompositeShape composite = new CompositeShape("Composite-Group");
composite.addShape(new Square(2.0, "Purple"));
composite.addShape(new Circle(1.0, "Orange"));
composite.addShape(new Square(3.0, "Pink"));
System.out.println("Composite Shape - Number of shapes: " + composite.getShapeCount());
System.out.println("Composite Shape - Total Area: " + composite.calculateArea());
System.out.println("Composite Shape - Total Perimeter: " + composite.calculatePerimeter());
System.out.println("Composite Shape - Color: " + composite.getColor());
// Test resizing composite shape
System.out.println("\nResizing composite shape by factor 2.0");
composite.resize(2.0);
System.out.println("Composite Shape - After resize - Total Area: " + composite.calculateArea());
System.out.println("Composite Shape - After resize - Total Perimeter: " + composite.calculatePerimeter());
// Test setting color for all shapes in composite
System.out.println("\nSetting color for all shapes in composite to 'Black'");
composite.setAllShapesColor("Black");
// Display individual shapes after modifications
System.out.println("\nIndividual shapes after modifications:");
for (Shape shape : composite.getShapes()) {
System.out.println("- Shape: " + shape.getClass().getSimpleName() + ", Color: " + shape.getColor() + ", Area: " + shape.calculateArea());
}
}
}
Loading…
Cancel
Save