Код: Выделить всё
public abstract class Shape {
abstract double surface_area();
abstract double volume();
}
public class Sphere extends Shape {
public double radius = 5;
private double sphere_Volume;
public double sphere_SA;
@Override
public double surface_area() {
sphere_SA = (4 * Math.PI * Math.pow(radius, 2));
return sphere_SA;
}
@Override
public double volume() {
sphere_Volume = (4/3 * Math.PI * Math.pow(radius, 3));
return sphere_Volume;
}
@Override
public String toString() {
String SA_String = String.valueOf(sphere_SA);
return SA_String;
}
}
import java.util.ArrayList;
public class ShapeArray {
public static void PrintShape (ArrayList shapeArray) {
for (int i = 0; i < shapeArray.size(); ++i) {
System.out.println(shapeArray.get(i));
}
}
public static void main(String[] args) {
ArrayList shapeArray = new ArrayList();
shapeArray.add(new Sphere());
shapeArray.add(new Cylinder());
shapeArray.add(new Cone());
PrintShape(shapeArray);
}
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... ing-method