public class Box double length double width double height B
public class Box
{
double length;
double width;
double height;
Box(double l, double w, double h)
{
length = l;
width = w;
height = h;
}// Box( )
double volume( )
{
return length * width * height;
}// end volume( )
}// end class Box
9.Add a Constructor to Class Box for a cube,which as 1 parameter,side
Solution
public class Box
{
double length;
double width;
double height;
Box(double l, double w, double h)
{
length = l;
width = w;
height = h;
}// Box( )
//Defines cube with all dimensions equal to parameter side.
Box(double side)
{
length = width = height = side;
}
double volume( )
{
return length * width * height;
}// end volume( )
}// end class Box
