Wednesday, February 4, 2009

THE CUBE PROGRAM

Programmer: Danver G. Palmiano
Date started: February 4, 2009
Date ended: February 5, 2009
Programmed name: Cube
Purpose: To create classes using Visibility Modifiers


public class Cube{

private double width;
private double length;
private double height;
private double volume;
private double area;

// constructor declaration

public Cube(double h, double l, double w)
{
width=h;
height=l;
length=w;
}

public Cube()
{

}

private double volume()
{

return (width*length*height);

}


private double area()
{

return (width*length);

}



public void setDimension(double newHeight, double newWidth, double newLength)
{
height=newHeight;
width=newWidth;
lenght=newLenght;
}

public void displayCube()
{
System.out.println(" Cube Dimansions");
System.out.println("Cube volume: " +volume());
System.out.println("Cube area: " +area());

}
}


//main method

class CubeTester{
public static void main(String args[]){

double l;
double w;
double h;


System.out.println("\n\n");
System.out.println("Cube with a Parameter");

Cube cube=new Cube(2,3,4);;
cube.displayCube();

System.out.println("The Cube object without a parameter");
System.out.println("\n\n");

Cube cube2=new Cube();
cube2.setDimension(l,w,h);
cube2.displayCube();
}
}



No comments:

Post a Comment