Skip to main content

Find the area of a rectangle & find the volume of a rectangular shaped box in JAVA.

DESCRIPTION:
class with a method to find the area of a rectangle.Create a subclass to find the volume of a rectangular shaped box.
CODING:
import java.util.Scanner;
class Rect
{
 public static void main(String [] args)
  {
    Scanner num=new Scanner(System.in);
    System.out.print("Input Width  Of Rectangle:");
    double w=num.nextDouble();
    System.out.print("Input Height Of Rectangle:");
    double h=num.nextDouble();
    System.out.print("Input Dept   Of Rectangle:"); 
    double d=num.nextDouble();
    VolumeRect R1=new VolumeRect();
    System.out.print("Volume of Rectangular Box:"+ R1.VolumeRect(w,h,d));
  }
}
class area
{
  public double AreaRect(double w,double h)
   {
     return w*h;
   }
}
class VolumeRect extends area
{
  public double VolumeRect(double w,double h,double d)
   {
     System.out.println("Area Of Rectangle:"+ AreaRect(w,h));
     return w*h*d;
   }
}

Comments