-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
50 lines (42 loc) · 1.37 KB
/
Test.java
File metadata and controls
50 lines (42 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
public class Test {
// Main method
public static void main(String[] args) {
// Create an array of geometric objects
GeometricObject[] shapes = {
new Circle(5),
new Rectangle(3, 1),
new Circle(),
new Circle(15),
new Rectangle(1, 2)
};
// Scale all Scalable geometric objects by a factor of 2.0
scaleGeometricObjects(shapes, 2.0);
// Rotate the first Rotable geometric object found in the array
rotateFirstGeometricObject(shapes);
// Display the array elements
displayGeometricObjects(shapes);
System.out.println("\n********************\n");
// Sort the array and display its elements
java.util.Arrays.sort(shapes);
displayGeometricObjects(shapes);
}
// Scales all Scalable geometric objects by the specified factor
public static void scaleGeometricObjects(GeometricObject[] arr, double factor) {
for (GeometricObject o : arr)
if (o instanceof Scalable)
((Scalable) o).scale(factor);
}
// Rotates the first Rotable geometric object found in the array
public static void rotateFirstGeometricObject(GeometricObject[] arr) {
for (GeometricObject o : arr)
if (o instanceof Rotatable) {
((Rotatable) o).rotate();
break;
}
}
// Display the array
public static void displayGeometricObjects(GeometricObject[] arr) {
for (GeometricObject o : arr)
System.out.printf("%s, area: %.2f\n", o.toString(), o.getArea());
}
}