writing a method to find the maximum surface area in an array of shapes
I'm really new to Java and I have down an idea of what I need to do for
these methods, I'm just trying to translate this into code haha I think
I'm just confused on which object is calling methods and so on and so
forth.
So I am trying to write a method called maxSurfaceArea that takes in an
array of shapes that are given specific dimensions and it finds the shape
that has the maximum surface area. So what I was trying to do was assign
the first index that contains a shape to a currentSurfaceArea and a
maxSurfaceeArea. Then the method needs to go to the next index of the
array, check the surface area, if it is bigger than the previous
maxSurfaceArea, then assign that new shape to maxSurfaceArea, and repeat
all the until the end of the array. In this program, I am calling this
method in the main method class but outside of that I have a class called
Shape that doesn't have anything in it. Also a Circle, Triangle, Rectangle
classes (each an individual class) that all extend from Shape. Also a
Sphere class (extends from Circle), Cylinder class (extends from Circle),
Prism class (extends from Rectangle), Tetrahedron class (extends from
Triangle).
Each of the classes have their own .computeArea methods and they are
output by a toString method that is called by the main class.
One of the things I am confused about is I know if I make maxSurfaceArea a
boolean that it cannot be converted to a "Shape" because that's the type
of array it's taking in. I just don't know. Any help would be much
appreciated.
public static Shape[] shapeList;
public static void main (String[] args)
{
shapeList = new Shape[8];
shapeList[0] = new Sphere(7.4);
shapeList[1] = new Prism(5,4.5,4);
shapeList[2] = new Tetrahedron(4,5);
shapeList[3] = new Cylinder(3.14, 4.5);
shapeList[4] = new Prism(1, 2, 3);
shapeList[5] = new Tetrahedron(2.34, 3.56);
shapeList[6] = new Sphere(2.5);
shapeList[7] = new Cylinder(6.7, 3.3);
for (int i = 0; i < shapeList.length; i++)
{
System.out.println(shapeList[i].toString());
}
}
public static void maxSurfaceArea(Shape[] shapeList)
{
boolean maxSurfaceArea, currentSurfaceArea;
for (int i = 0; i < shapeList.length; i++)
{
currentSurfaceArea = (shapeList[i]);
maxSurfaceArea = (shapeList[i])
if (shapeList[i].computeArea() > )
{
}
}
No comments:
Post a Comment