I need a method or way to store all values(r,h,area,volume) in a array for the cylinder class below. The array should contain the values in in ascending order.This is the code below to find area and volume.
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Double> shapeProperties = new ArrayList<Double>();
double tc, r, h;
System.out.println("Enter # of test cases");
tc = sc.nextInt();
for (int i = 0; i < tc; i++) {
System.out.println("Enter base radius");
r = sc.nextInt();
System.out.println("Enter height");
h = sc.nextInt();
if (tc > 10 || r > 10 || h > 10) {
System.out.println("Please enter a value under 10");
break;
} else {
System.out.println("Radius r= " + r);
System.out.println("Height h= " + h);
System.out.println("Volume = " + getVolume(r, h));
System.out.println("Area = " + getArea(r, h));
ArrayList<Double> properties = sortPropertiesInArray(r, h, getArea(r,h), getVolume(r,h));
}
}
}
static ArrayList<Double> sortPropertiesInArray(double r, double h, double area, double volume) {
ArrayList<Double> shapeProperties = new ArrayList<Double>();
shapeProperties.add(r);
shapeProperties.add(h);
shapeProperties.add(area);
shapeProperties.add(volume);
Collections.sort(shapeProperties);
return shapeProperties;
}
public static double getVolume(double r, double h) {
return Math.PI * r * r * h;
}
public static double getArea(double r, double h) {
return 2 * Math.PI * r * (r * h);
}
}