import java.awt.*; public class RectangleDemo { public static void main(String[] args) { Rectangle rect = new Rectangle(10, 20, 30, 40); // creates a Rectangle object double centerX = rect.getCenterX(); // gets the center X-coordinate of the Rectangle System.out.println("Center X-coordinate: " + centerX); } }
Center X-coordinate: 25.0
import java.awt.*; public class RectangleDemo { public static void main(String[] args) { Rectangle rect = new Rectangle(10, 20, 30, 40); // creates a Rectangle object boolean isPointInside = isPointInsideRect(rect, 15, 30); // checks if the point (15, 30) is inside the Rectangle System.out.println("Is point inside the Rectangle? " + isPointInside); } // method to check if a point is inside a Rectangle public static boolean isPointInsideRect(Rectangle rect, int x, int y) { return rect.contains(x, y); } }
Is point inside the Rectangle? truePackage library: java.awt