42.6k views
3 votes
Write a Box class whose init method takes three parameters and uses them to initialize the private length, width and height data members of a Box. It should also have a method named volume that returns the volume of the Box. It should have get methods named get_length, get_width, and get_height.

User Martinsb
by
7.0k points

1 Answer

11 votes

Answer:

Answered below

Step-by-step explanation:

//Program is written in Java programming //language

Class Box{

private double length;

private double width;

private double height;

Box(double len, double wid, double hgt){

length = len;

width = wid;

height = hgt;

}

public double volumeOfBox( ){

double volume = length * width * height;

return volume;

}

public double getLength( ){

return length;

}

public double getWidth( ){

return width;

}

public double getHeight( ){

return height;

}

}

User Manzur Alahi
by
6.5k points