Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You have to create a program that can compute the Surface Area and Volumes of va

ID: 3548567 • Letter: Y

Question

 You have to create a program that can compute the Surface Area and Volumes of  various containers that are all "Right Prisms".  This means that the ends of the  container are identical and the sides are perpendicular to the ends.   Each of your containers has different shapes: Circular, Rectangular, Triangular, and  Regular Polygon.  All of these containers are derived from a common abstract Container class.  You will then create a class called ContainerCollection which will contain an array  of all of the possible Container classes.  This class will provide methods to  compute the totalVolume and the totalSurfaceArea of all Containers in the  ContainerCollection.   The geometric equations for area and perimeter are provided for the required shapes  as follows:  

Perimeter Calculations (for your getTopPerimeter methods)

  • Circle-
    return 2.0 * Math.PI * radius;
  • Rectangle-
    return 2.0 * (width + length);
  • Triange-
    return side_a + side_b + side_c;
  • Regular Polygon-
    return numSides * side;

Area Calculations (for your getTopArea methods)

  • Circle-
    return Math.PI * radius * radius;
  • Rectangle-
    return width * length;
  • Triange-
    double s = (side_a + side_b + side_c)/2.0;
    return Math.sqrt(s*(s-side_a)*(s-side_b)*(s-side_c));
  • Regular Polygon-
    return numSides * side * side / ( 4*Math.tan(Math.PI/numSides));
// ******************************************************** // *******   Starter Code  ******************************** // ******************************************************** abstract class Container {     double height;     Container(double height)     {         this.height = height;     }     abstract double getTopArea();     abstract double getTopPerimeter();          double getVolume()     {         return height * getTopArea();     }     double getSurfaceArea()     {         return 2*getTopArea() + height * getTopPerimeter();     } } class CircularContainer extends Container {         // add appropriate data definitions     CircularContainer(double height, double radius)     {         // Fill in details     }     // implement required abstract methods } class RectangularContainer extends Container {     // add appropriate data definitions     RectangularContainer(double height, double width, double length)     {         // Fill in details     }     // implement required abstract methods } class TriangularContainer extends Container {     // add appropriate data definitions     TriangularContainer(double height, double side_a, double side_b, double side_c)     {         // Fill in details     }     // implement required abstract methods } class RegularPolygonContainer extends Container {     // add appropriate data definitions     RegularPolygonContainer(double height, double side, int numSides)     {         // Fill in details     }     // implement required abstract methods } class ContainerCollection {     Container[] collection;     int numContainers;     int containerCount=0;          ContainerCollection(int numContainers)     {         // Fill in details     }          void addContainer( Container c)     {         // Fill in details                 // Don't forget to check to see if there is enough room                 // in collection before adding.  Complain if you can't add Container.     }          double getTotalVolume()     {         // Fill in details to return the total volume of                 // all Containers in collection     }          double getTotalSurfaceArea()     {         // Fill in details to return the total surface area of                 // all Containers in collection     }          public static void main(String[] args)     {         ContainerCollection cc = new ContainerCollection(10);                  cc.addContainer(new CircularContainer(10., 2.0)); // height, radius         cc.addContainer(new RectangularContainer(10., 2.0, 3.0)); // height, width, length         cc.addContainer(new TriangularContainer(10., 4.0, 3.0, 5.0)); // height, side_a, side_b, side_c         cc.addContainer(new RegularPolygonContainer(10., 1.0, 4)); // height, side, num_sides                  cc.addContainer(new CircularContainer(5., 2.0)); // height, radius         cc.addContainer(new RectangularContainer(5., 2.0, 3.0)); // height, width, length         cc.addContainer(new TriangularContainer(5., 4.0, 3.0, 5.0)); // height, side_a, side_b, side_c         cc.addContainer(new RegularPolygonContainer(5., 1.0, 4)); // height, side, num_sides                  cc.addContainer(new CircularContainer(2., 2.0)); // height, radius         cc.addContainer(new RectangularContainer(2., 2.0, 3.0)); // height, width, length         cc.addContainer(new TriangularContainer(2., 4.0, 3.0, 5.0)); // height, side_a, side_b, side_c         cc.addContainer(new RegularPolygonContainer(2., 1.0, 4)); // height, side, num_sides                  System.out.println("Total Volume of all containers = " + cc.getTotalVolume());         System.out.println("Total Surface Area of all containers = " + cc.getTotalSurfaceArea());         ContainerCollection cc2 = new ContainerCollection(2);         cc2.addContainer(new RectangularContainer(5.504, 2.0, 3.0)); // height, width, length         cc2.addContainer(new RectangularContainer(9., 2.0, 3.0)); // height, width, length         cc2.addContainer(new RectangularContainer(8., 2.0, 3.0)); // height, width, length         System.out.println("Total Volume of all containers for cc2 = " + cc2.getTotalVolume());     } }

Explanation / Answer

abstract class Container {

double height;

Container(double height)

{

this.height = height;

}

abstract double getTopArea();

abstract double getTopPerimeter();

  

double getVolume()

{

return height * getTopArea();

}

double getSurfaceArea()

{

return 2*getTopArea() + height * getTopPerimeter();

}

}


class CircularContainer extends Container

{

// add appropriate data definitions

double radius;

CircularContainer(double height, double radius)

{

super(height);

this.radius = radius;

  

}

// implement required abstract methods

double getTopArea()

{

return Math.PI * radius * radius;

}

double getTopPerimeter()

{

return 2.0 * Math.PI * radius;

}

}


class RectangularContainer extends Container

{

// add appropriate data definitions

double width;

double length;

RectangularContainer(double height, double width, double length)

{

// Fill in details

super(height);

this.width = width;

this.length = length;

}

// implement required abstract methods

double getTopArea()

{

return width * length;

}

double getTopPerimeter()

{

return 2.0 * (width + length);

}

}


class TriangularContainer extends Container

{

// add appropriate data definitions

double side_a, side_b, side_c;

TriangularContainer(double height, double side_a, double side_b, double side_c)

{

// Fill in details

super(height);

this.side_a = side_a;

this.side_b = side_b;

this.side_c = side_c;

  

}

// implement required abstract methods

double getTopArea()

{

double s = (side_a + side_b + side_c)/2.0;

return Math.sqrt(s*(s-side_a)*(s-side_b)*(s-side_c));

}

double getTopPerimeter()

{

return side_a + side_b + side_c;

}

}



class RegularPolygonContainer extends Container

{

// add appropriate data definitions

double side;

int numSides;

RegularPolygonContainer(double height, double side, int numSides)

{

// Fill in details

super(height);

this.side = side;

this.numSides =numSides;

}

// implement required abstract methods

double getTopArea()

{

return numSides * side * side / ( 4*Math.tan(Math.PI/numSides));

}

double getTopPerimeter()

{

return numSides * side;

}

}


class ContainerCollection

{

Container[] collection;

int numContainers;

int containerCount;

double totalv;

double totala;

  

ContainerCollection(int numContainers)

{

// Fill in details

this.numContainers = numContainers;

this.containerCount =0;

this.totalv=0;

this.totala=0;

collection = new Container[numContainers];

}

  

void addContainer( Container c) throws NullPointerException

{

// Fill in details

// Don't forget to check to see if there is enough room

// in collection before adding. Complain if you can't add Container.

if(containerCount>=numContainers)

{

System.out.println("Sorry no more containers allowed");

}

else

{

collection[containerCount] = c;

containerCount++;

}

}

  

double getTotalVolume()

{

// Fill in details to return the total volume of

// all Containers in collection

for(int i=0;i<containerCount;i++)

{

totalv+=collection[i].getVolume();

}

return totalv;

}

  

double getTotalSurfaceArea()

{

// Fill in details to return the total surface area of

// all Containers in collection

for(int i=0;i<containerCount;i++)

{

totala+=collection[i].getSurfaceArea();

}

return totala;

}

  

public static void main(String[] args) throws Exception

{

ContainerCollection cc = new ContainerCollection(10);

  

cc.addContainer(new CircularContainer(10., 2.0)); // height, radius

cc.addContainer(new RectangularContainer(10., 2.0, 3.0)); // height, width, length

cc.addContainer(new TriangularContainer(10., 4.0, 3.0, 5.0)); // height, side_a, side_b, side_c

cc.addContainer(new RegularPolygonContainer(10., 1.0, 4)); // height, side, num_sides

  


cc.addContainer(new CircularContainer(5., 2.0)); // height, radius

cc.addContainer(new RectangularContainer(5., 2.0, 3.0)); // height, width, length

cc.addContainer(new TriangularContainer(5., 4.0, 3.0, 5.0)); // height, side_a, side_b, side_c

cc.addContainer(new RegularPolygonContainer(5., 1.0, 4)); // height, side, num_sides

  


cc.addContainer(new CircularContainer(2., 2.0)); // height, radius

cc.addContainer(new RectangularContainer(2., 2.0, 3.0)); // height, width, length

cc.addContainer(new TriangularContainer(2., 4.0, 3.0, 5.0)); // height, side_a, side_b, side_c

cc.addContainer(new RegularPolygonContainer(2., 1.0, 4)); // height, side, num_sides

  

System.out.println("Total Volume of all containers = " + cc.getTotalVolume());

System.out.println("Total Surface Area of all containers = " + cc.getTotalSurfaceArea());


ContainerCollection cc2 = new ContainerCollection(2);

cc2.addContainer(new RectangularContainer(5.504, 2.0, 3.0)); // height, width, length

cc2.addContainer(new RectangularContainer(9., 2.0, 3.0)); // height, width, length

cc2.addContainer(new RectangularContainer(8., 2.0, 3.0)); // height, width, length

System.out.println("Total Volume of all containers for cc2 = " + cc2.getTotalVolume());

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote