JAVA-Create an interface called Shape3D-Put this class in a package called shapePack and use it in another classes named Parallelepiped, Cube and Sphere to calculate volume and surface area

Q. Create an interface called Shape3D with the following: 
a. Symbolic constant – PI 
b. Prototype of methods calcVolume() and calcSurfaceArea() 
Put this class in a package called shapePack and use it in another classes named Parallelepiped, Cube and Sphere to calculate volume and surface area for each shape.



shape3d.java :
package shapepack;
public interface shape3d
{
public final static double PI=3.143;
public void calc_volume();
public void calc_surfacearea();


shapetest.java :
import shapepack.shape3d;
class parallelepiped implements shape3d
{
int l,b,h;
parallelepiped(int x,int y,int z)
{
l=x;
b=y;
h=z;
}
public void calc_volume()
{
System.out.println("volume of the parallelepiped: "+(l*b*h));
}
public void calc_surfacearea()
{
System.out.println("surfacearea of the parallelepiped: "+(l*b+b*h+h*l));
}
}
class shapetest
{
public static void main(String args[])
{
parallelepiped ob=new parallelepiped(5,7,9);
ob.calc_volume();
ob.calc_surfacearea();
}

}
Output:
volume of the parallelepiped: 315
surfacearea of the parallelepiped: 143

shapetestcube.java :
import shapepack.shape3d;
class cube implements shape3d
{
int l,b,h;
cube(int x,int y,int z)
{
l=x;
b=y;
h=z;
}
public void calc_volume()
{
System.out.println("volume of the cube: "+(l*l*l));
}
public void calc_surfacearea()
{
System.out.println("surfacearea of the cube: "+(6*l*l));
}
}
class shapetestcube
{
public static void main(String args[])
{
cube ob=new cube(5,7,9);
ob.calc_volume();
ob.calc_surfacearea();
}

}
Output:
volume of the cube: 125
surfacearea of the cube: 150

shapetestsphere.java :
import shapepack.shape3d;
class sphere implements shape3d
{
int l,b,h;
sphere(int x,int y,int z)
{
l=x;
b=y;
h=z;
}
public void calc_volume()
{
System.out.println("volume of the sphere: "+4*PI*(l*l*l)/3);
}
public void calc_surfacearea()
{
System.out.println("surfacearea of the sphere: "+(4*PI*l*l));
}
}
class shapetestsphere
{
public static void main(String args[])
{
sphere ob=new sphere(5,7,9);
ob.calc_volume();
ob.calc_surfacearea();
}
}

Output:
volume of the sphere: 528
surfacearea of the sphere: 314

//if you have any problem, comment below

Comments