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

Hello I need help creating the following program in Java Three Dimensional Figur

ID: 3727363 • Letter: H

Question

Hello I need help creating the following program in Java

Three Dimensional Figures

In keeping with the geometry theme that has been our object-oriented programming experience, you will create an abstract class named Shape. The class Shape should be defined as follows:

- sides (int) //A variable that holds the number of sides the face of the shape has.
You should also have 3 constructors:
- a no-arg constructor that initializes the number of sides to 0
- a parameterized constructor that receives an int parameter. The method should call the setSides method
- copy constructor
You should also define the following methods:
- setSides(int) //setter method for the private member
- getSides() //getter method for the private member
- calcArea() (double) //An abstract method.
- toString() //returns a String that gives the number of sides the base shape has.

This Shape class is to be extended by the following classes:

- ThreeDimensional (an abstract class). This class should have a private instance member faces (int), that stores the number of faces of the three dimensional object. Create a no-arg as well as a parameterized constructor. Also define getters and setters for the private member variable and define an abstract method calcVolume() that returns a double value. The class should also have a toString method that lets the user know how many faces the three dimensional object has.

- Rectangle (you may use the one you have already created in previous assignments, with modifications)
- Triangle
- Circle (you may use the one from previous assignment with modifications)

All these classes should define the method calcArea() based on its own respective geometry. Also, define a toString() method that lets the user know the type of two dimensional shape and the superclass information about how many sides the base shape has.

The following classes should extend the ThreeDimensional class:

- Cylinder
- Box
- TriPrism

Each of these should define surfaceArea() and calcVolume() for the respective geometry. You may chose to use aggregation to help define the Cylinder, Box, and TriPrism classes. Also, define a toString() method that lets the user know the type of three dimensional shape and the superclass information about how many sides the base shape has.

Create a demo class named ShapeDemo that demonstrates the various two dimensional and three dimensional objects. Define an ArrayList of shapes. You are to create 10 Shape objects made up of Rectangle, Circle, Triangle, Cylinder, Box, TriPrism objects. Use an enhanced for loop to display each of the Shapeitems.

Explanation / Answer

Note : Could you please check the output .If you required any changes Just intimate.I will modify it.Thank You.

_______________

Shape.java

public abstract class Shape {
   private int sides;

   public Shape() {
       this.sides=0;
   }

   public Shape(int sides) {
       super();
       this.sides = sides;
   }

   public int getSides() {
       return sides;
   }

   public void setSides(int sides) {
       this.sides = sides;
   }
   public abstract void calcArea();

   @Override
   public String toString() {
       return "This Shape has [sides=" + sides + "]";
   }
        

}

_______________

TwoDimensional.java

public abstract class TwoDimensional extends Shape {

   private int faces;

   public TwoDimensional(int faces,int sides) {
       super(sides);
       this.faces = faces;
   }

   public TwoDimensional() {
       super();
      
   }

   public int getFaces() {
       return faces;
   }

   public void setFaces(int faces) {
       this.faces = faces;
   }

   @Override
   public String toString() {
       System.out.println(super.toString());
       return "This is TwoDimensional [faces=" + faces + "]";
   }
  

}

_________________

Rectangle.java

public class Rectangle extends TwoDimensional {


   private double height;
   private double width;
   double area;
  
  
   public Rectangle(double height, double width,int faces,int sides) {
       super(faces,sides);
       this.height = height;
       this.width = width;
   }
  
  
   public double getHeight() {
       return height;
   }


   public void setHeight(double height) {
       this.height = height;
   }


   public double getWidth() {
       return width;
   }


   public void setWidth(double width) {
       this.width = width;
   }


   @Override
   public void calcArea() {
       area=width* height;
   //   System.out.println("Area of Rectangle:"+area);
      

   }


   @Override
   public String toString() {
       System.out.println("----------------------------------------");
       System.out.println(super.toString());
       this.calcArea();
       return "Rectangle [height=" + height + ", width=" + width + ", area="
               + area + "]";
   }
  

}

_________________

Triangle.java

public class Triangle extends TwoDimensional {

  
   protected double base=0.0;
   protected double height=0.0;
   double area;
       public Triangle() {
          
       }

       public Triangle(double base,double height,int faces,int sides) {
           super(faces, sides);
           this.base=base;
           this.height=height;
       }

   @Override
   public void calcArea() {
       area=0.5*base*height;
// System.out.println("Area Of Traingle: "+area);
   }

   @Override
   public String toString() {
       System.out.println("----------------------------------------");
       System.out.println(super.toString());
       this.calcArea();
       return "Triangle [base=" + base + ", height=" + height + ", area="
               + area + "]";
   }

}

_________________

Circle.java

public class Circle extends TwoDimensional {
private double radius;

   public Circle(double radius,int faces,int sides) {
   super(faces,sides);
   this.radius = radius;
  
}
  
  
   public Circle(int faces,int sides) {
       super(faces,sides);
   }


   public double getRadius() {
       return radius;
   }


   public void setRadius(double radius) {
       this.radius = radius;
   }


   double area;
   @Override
   public void calcArea() {
       area=3.14*radius*radius;
//System.out.println("Area of circle:"+area);
   }


   @Override
   public String toString() {
       System.out.println("----------------------------------------");
       System.out.println(super.toString());
       this.calcArea();
       return "Circle [radius=" + radius + ", area=" + area + "]";
   }


}

_____________________

ThreeDimensional.java

public abstract class ThreeDimensional extends Shape {
   private int faces;

   public ThreeDimensional() {
       super();
   }

   public ThreeDimensional(int faces, int sides) {
       super(sides);
       this.faces = faces;
   }

   public int getFaces() {
       return faces;
   }

   public void setFaces(int faces) {
       this.faces = faces;
   }

   public abstract double calcVolume();

   @Override
   public String toString() {
       System.out.println(super.toString());
       return "This is ThreeDimensional [faces=" + faces + "]";
   }

}

_________________

Cylinder.java

import java.text.DecimalFormat;

public class Cylinder extends ThreeDimensional {

   private double radius;
   private double height;
   double surfacearea;
   double volume;
   @Override
   public double calcVolume() {
       volume=3.14*radius*radius*height;
       //System.out.println("Volume of Cylinder:"+volume);
       return volume;
   }

   @Override
   public void calcArea() {
       surfacearea=2*3.14*radius*(radius+height);
       //System.out.println("Surface area of Cyclinder:"+surfacearea);

   }

   public double getRadius() {
       return radius;
   }

   public void setRadius(double radius) {
       this.radius = radius;
   }

   public double getHeight() {
       return height;
   }

   public void setHeight(double height) {
       this.height = height;
   }

   public Cylinder(double radius, double height,int faces,int sides) {
       super(faces,sides);
       this.radius = radius;
       this.height = height;
   }

   public Cylinder() {
       super();
   }

   @Override
   public String toString() {
       //DecimalFormat class is used to format the output
               DecimalFormat df=new DecimalFormat("#.##");
       System.out.println("----------------------------------------");
       System.out.println(super.toString());
       this.calcArea();
       this.calcVolume();
       return "Cylinder [radius=" + radius + ", height=" + height
               + ", surfacearea=" + surfacearea + ", volume=" +df.format(volume)+ "]";
   }

}

________________

Box.java

public class Box extends ThreeDimensional {
private double length;
private double width;
private double height;
double area;
double volume;
   public Box() {
   super();
}

   public Box(double length, double width, double height,int faces,int sides) {
       super(faces,sides);
       this.length = length;
       this.width = width;
       this.height = height;
   }

   public double getLength() {
       return length;
   }

   public void setLength(double length) {
       this.length = length;
   }

   public double getWidth() {
       return width;
   }

   public void setWidth(double width) {
       this.width = width;
   }

   public double getHeight() {
       return height;
   }

   public void setHeight(double height) {
       this.height = height;
   }

   @Override
   public double calcVolume() {
       volume=length*width*height;
return volume;
   }

   @Override
   public void calcArea() {
       area=2*(length*width+width*height+height*length);
   }

   @Override
   public String toString() {
       System.out.println("----------------------------------------");
       System.out.println(super.toString());
       this.calcVolume();
       this.calcArea();
       return "Box [length=" + length + ", width=" + width + ", height="
               + height + ", area=" + area + ", volume=" + volume + "]";
   }

}

____________________

TriPrism.java

public class TriPrism extends ThreeDimensional {
private double length;
private double width;
private double height;
private double side;
double area;
double volume;
  
  
   public TriPrism() {
   super();
}

   public TriPrism(double length, double width, double height, double side,int faces,int sides) {
   super(faces,sides);
   this.length = length;
   this.width = width;
   this.height = height;
   this.side = side;
}

   public double getLength() {
       return length;
   }

   public void setLength(double length) {
       this.length = length;
   }

   public double getWidth() {
       return width;
   }

   public void setWidth(double width) {
       this.width = width;
   }

   public double getHeight() {
       return height;
   }

   public void setHeight(double height) {
       this.height = height;
   }

   public double getSide() {
       return side;
   }

   public void setSide(double side) {
       this.side = side;
   }

   @Override
   public double calcVolume() {
       volume=0.5*length*width*height;
   //   System.out.println("Volume of Triprism:"+volume);
       return volume;
   }

   @Override
   public void calcArea() {
   area=width*height+length*width+length*height+length*side;
// System.out.println("Area of TriPrism:"+area);
   }

   @Override
   public String toString() {
       System.out.println("----------------------------------------");
       System.out.println(super.toString());
       this.calcArea();
       this.calcVolume();
       return "TriPrism [length=" + length + ", width=" + width + ", height="
               + height + ", side=" + side + ", area=" + area + ", volume="
               + volume + "]";
   }

}

__________________

ShapeDemo.java

import java.util.ArrayList;

public class ShapeDemo {

   public static void main(String[] args) {
       //Creating an ArrayList
       ArrayList<Shape> shapes = new ArrayList();
       //Adding objects to an ArrayList
       shapes.add(new Rectangle(10, 5,1,12));
       shapes.add(new Triangle(20, 10,1,3));
       shapes.add(new Circle(5.5,1,0));
       shapes.add(new Rectangle(6, 4,1,12));
       shapes.add(new Cylinder(4,7,3,0));
       shapes.add(new Box(4,5,6,6,12));
       shapes.add(new Circle(3.5,1,0));
       shapes.add(new TriPrism(3, 4, 5, 2,4,6));
       shapes.add(new Cylinder(2,5,3,0));
       shapes.add(new TriPrism(2, 3, 4, 2,4,6));
       //Iterating over ArrayList.
       for(Shape shape:shapes)
       {
           System.out.println(shape.toString());
          
       }

   }

}

__________________

Output:

----------------------------------------
This Shape has [sides=12]
This is TwoDimensional [faces=1]
Rectangle [height=10.0, width=5.0, area=50.0]
----------------------------------------
This Shape has [sides=3]
This is TwoDimensional [faces=1]
Triangle [base=20.0, height=10.0, area=100.0]
----------------------------------------
This Shape has [sides=0]
This is TwoDimensional [faces=1]
Circle [radius=5.5, area=94.985]
----------------------------------------
This Shape has [sides=12]
This is TwoDimensional [faces=1]
Rectangle [height=6.0, width=4.0, area=24.0]
----------------------------------------
This Shape has [sides=0]
This is ThreeDimensional [faces=3]
Cylinder [radius=4.0, height=7.0, surfacearea=276.32, volume=351.68]
----------------------------------------
This Shape has [sides=12]
This is ThreeDimensional [faces=6]
Box [length=4.0, width=5.0, height=6.0, area=148.0, volume=120.0]
----------------------------------------
This Shape has [sides=0]
This is TwoDimensional [faces=1]
Circle [radius=3.5, area=38.465]
----------------------------------------
This Shape has [sides=6]
This is ThreeDimensional [faces=4]
TriPrism [length=3.0, width=4.0, height=5.0, side=2.0, area=53.0, volume=30.0]
----------------------------------------
This Shape has [sides=0]
This is ThreeDimensional [faces=3]
Cylinder [radius=2.0, height=5.0, surfacearea=87.92, volume=62.8]
----------------------------------------
This Shape has [sides=6]
This is ThreeDimensional [faces=4]
TriPrism [length=2.0, width=3.0, height=4.0, side=2.0, area=30.0, volume=12.0]

_________Thank You

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