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

create the following classes: a) a parent class called Shape3D. Declare Protecte

ID: 3766832 • Letter: C

Question

create the following classes:

a) a parent class called Shape3D. Declare Protected Instance variables: volume and surfaceArea (both double) Write a default constructor. This constructor should set volume and surfaceArea to 0.

b) a class derived from Shape3D. The name of this class is your choice. Declare additional private variables as needed. It will inherit volume and surfaceArea from Shape3D. For example, if the shape is a cube, then it needs a variable for side. Write a default constructor. Write additional constructors if you see a use for them. Write accessors and mutators for the private variables.

Write calculateVolume( ) – a public method that will calculate the volume of this shape using the appropriate formula. For example, if the shape is a cube, then volume = side * side * side. The method should set the volume variable. The should also return the value of volume.

Write calculateSurface ( ) - a public method that will calculate the volume of this shape using the appropriate formula. For example, if the shape is a cube, then surfaceArea = 6 * side * side. The method should set the surfaceArea variable. The should also return the value of surfaceArea.

c) another class derived from Shape3D. The name of this class is your choice.

Declare additional private variables as needed. It will inherit volume and surfaceArea from Shape3D. For example, if the shape is a cube, then it needs a variable for side. Write a default constructor. Write additional constructors if you see a use for them. Write accessors and mutators for the private variables.

Write calculateVolume( ) – a public method that will calculate the volume of this shape using the appropriate formula. For example, if the shape is a cube, then volume = side * side * side. The method should set the volume variable. The should also return the value of volume.

Write calculateSurface ( ) - a public method that will calculate the volume of this shape using the appropriate formula. For example, if the shape is a cube, then surfaceArea = 6 * side * side. The method should set the surfaceArea variable. The should also return the value of surfaceArea.

d) to test your classes, write a driver program.

I know its a lot, but I really am lost, and do need a lot of help, this is for a java program, and just dont know where to go with it, I've been working on it, but I cant even get part A, so any and all help would be greatly appreciated. Thank you in advanced.

Explanation / Answer

public abstract class Shape3D
{
    public abstract double area();
    public abstract double perimeter();
}

Rectangle.java

public class Rectangle extends Shape3D
{
private final double width, height, area, perimeter;

public Rectangle(double width, double height)
{
    this.width = width;
    this.height= height;
    this.area = width * height;
    this.perimeter = 2 * (width + height);
}


public double getArea()
{
    return this.area;
}


public double getPerimeter()
{
    return this.perimeter;
}

}

Circle.java

public class Circle extends Shape3D{
    private final double radius;
    final double pi = Math.PI;

    public Circle() {
        this(1);
    }
    public Circle(double radius) {
        this.radius = radius;
    }


    public double area()

{
   
        return pi * Math.pow(radius, 2);
    }

    public double perimeter()

{

        return 2 * pi * radius;
    }
}

Triangle.java

public class Triangle extends Shape3D{
    private final double a, b, c; // sides

    public Triangle() {
        this(1,1,1);
    }
    public Triangle(double a, double b, double c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }


    public double area()

{
       
        double s = (a + b + c) / 2;
        return Math.sqrt(s * (s - a) * (s - b) * (s - c));
    }


    public double perimeter()

{
        return a + b + c;
    }
}

TestShape.java

public class TestShape3D{
    public static void main(String[] args)

{


        double width = 5, length = 7;
        Shape3Drectangle = new Rectangle(width, length);
        System.out.println("Rectangle width: " + width + " and length: " + length
                + " Resulting area: " + rectangle.area()
                + " Resulting perimeter: " + rectangle.perimeter() + " ");

   
        double radius = 5;
        Shape3Dcircle = new Circle(radius);
        System.out.println("Circle radius: " + radius
            + " Resulting Area: " + circle.area()
            + " Resulting Perimeter: " + circle.perimeter() + " ");

   
        double a = 5, b = 3, c = 4;
        Shape3Dtriangle = new Triangle(a,b,c);
        System.out.println("Triangle sides lengths: " + a + ", " + b + ", " + c
                + " Resulting Area: " + triangle.area()
                + " Resulting Perimeter: " + triangle.perimeter() + " ");
    }
}