Box.java
29 linesjava
DOWNLOAD
1// Aim: Program to perform Box operations (Volume).
2import java.util.Scanner;
3public class Box{
4    double width;
5    double height;
6    double depth;
7    public Box(double w, double h, double d){
8        width = w;
9        height = h;
10        depth =  d;
11    }
12
13public double volume(){
14    return width*height*depth;
15}
16    public static void main(String args[]){
17        try (Scanner sc = new Scanner(System.in)) {
18            System.out.print("Enter the width of the box : ");
19            double w = sc.nextDouble();
20            System.out.print("Enter the height of the box : ");
21            double h = sc.nextDouble();
22            System.out.print("Enter the depth of the box : ");
23            double d = sc.nextDouble();
24            Box b = new Box(w,h,d);
25            System.out.println("The volume of the box is : "+b.volume());
26        }
27    }
28}
29