Showing posts with label simple class creation. Show all posts
Showing posts with label simple class creation. Show all posts

Sunday, 13 November 2016

Java Program to find the Volume of a Box

Volume of a Box in Java


                  The below program demonstrates simple class creation and perform volume calculation of a box.


Program:


class Box {
double width;
double height;
double depth;
}
public class BoxJavaProgram {
    public static void main(String[] args){
        Box mybox = new Box();
        double vol;
        mybox.width = 20;
        mybox.height = 30;
        mybox.depth = 10;
        vol = mybox.width * mybox.height * mybox.depth;
        System.out.println("Volume is " + vol);
    }
}

Output:


Volume is 6000.0