Write programs in com. The demo package defined in the class, write the Test in the same package, in the main () method to write the following code:
Double d=0.0;
Shape [] shapes=new Shape [5];
for(int i=0; i
D=Math. The random ();
If (d> 0.5) {
Shapes [I]=new Circle (1);
} else {
Shapes [I]=new Rectangle (1, 2);
}
}
Double sumArea=sum (shapes);
System. The out. Printf (". The area of the shape=% 2 f, sumArea);
}
Here: sum (Shpae shapes []) method is to Test the static method of a class, you need to define the method,
Below is the application of a run results:
The shape of the total area=12.28