
Box
Height : Integer Length: Integer Depth: Integer Colour: String
Method computeVolume : double
Based on the class notation above, write a full Java program that includes class Box() and its attributes. The program will ask user to input the height, length, depth and colour of an object Box B1. The class method will return the volume of the box in double. The main method will display all the box attributes and its volume.

Hi Friend,
Try the following code:
import java.util.*;
class BoxVolume{
int Length=0;
int Depth=0;
int Height=0;
BoxVolume(int l,int d,int h){
Length=l;
Depth=d;
Height=h;
}
public void display(){
System.out.println("Length:"+Length+"\nDepth:"+Depth+"\nHeight:"+Height);
}
public double findVolume(){
double v=Length*Depth*Height;
return v;
}
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter Length: ");
int l=input.nextInt();
System.out.print("Enter Depth: ");
int d=input.nextInt();
System.out.print("Enter Height: ");
int h=input.nextInt();
BoxVolume b=new BoxVolume(l,d,h);
b.display();
System.out.println("Volume="+b.findVolume());
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.