Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

public class CalculatingVolume {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

Volume shape1 = new Volume();

shape1.setlength (20);

shape1.setheight (10);

shape1.setwidth (15);

shape1.getVolume ();

Volume shape2 = new Volume();

shape2.setlength (50);

shape2.setheight (10);

shape2.setwidth (15);

shape2.getVolume ();

Volume shape3 = new Volume(10, 20, 30);

shape3.getVolume ();

**Create a new Java class (right click then new)


public class Volume {

private double lenght;


private double height;

private double width;

public void setlength(double newlength)

this.lenght = newlength;

public void setheight(double newheight)

this.height = newheight;

public void setwidth(double newwidth)

this.width = newwidth;

Volume ()

Volume (double height, double length, double width)

this.lenght = length;

this.height = height;

this.width = width;

void getVolume ()
{

System.out.println("The volume is" + this.height * this.lenght * this.width);

You might also like