0% found this document useful (0 votes)
35 views

Create A New Java Class (Right Click Then New)

This document contains code to calculate the volumes of 3 shapes using a Volume class. It creates Volume objects, sets their length, width, and height properties, and calls the getVolume method to output the calculated volume. The Volume class defines properties to store the dimensions and a constructor to set them. It also contains a getVolume method that calculates and prints the volume by multiplying the stored dimension properties.

Uploaded by

Dyzzer Lei
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Create A New Java Class (Right Click Then New)

This document contains code to calculate the volumes of 3 shapes using a Volume class. It creates Volume objects, sets their length, width, and height properties, and calls the getVolume method to output the calculated volume. The Volume class defines properties to store the dimensions and a constructor to set them. It also contains a getVolume method that calculates and prints the volume by multiplying the stored dimension properties.

Uploaded by

Dyzzer Lei
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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