Wednesday, February 4, 2009

Cube Programme

// programmer:Junnaliza L.Arreglado
// date started: February 4, 2009
// date ended: February 4, 2009
// Programme name: Cube
// programme purpose: To create classes using Visibility Modifiers


public class Cube{


// variable declarations


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



// constructor declaration


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

public Cube()
{

}


// method declarationS


private double volume()
{

return (width*length*height);

}


private double area()
{

return (width*length);

}


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

public void displayCube()
{
System.out.println("Cube Dimensions:");
System.out.println("The VOLUME of the Cube is" +volume());
System.out.println("The AREA of the Cube is" +area());

}
}

___________________________________________________________________

// programmer:Junnaliza L.Arreglado
// date started: February 4, 2009
// date ended: February 4, 2009
// Programme name: Cube
// programme purpose: To create classes using Visibility Modifiers

import java.util.Scanner;
class CubeTester1
{
public static void main(String args[])
{

double l;
double w;
double h;


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

Cube firstCube=new Cube(2,2,2);;
firstCube.displayCube();

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

Scanner a=new Scanner(System.in);
System.out.println("enter the value of the length:");
l=a.nextDouble();

Scanner b=new Scanner(System.in);
System.out.println("enter the value of the height:");
w=b.nextDouble();

Scanner c=new Scanner(System.in);
System.out.println("enter the value of the width:");
h=c.nextDouble();



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

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



No comments:

Post a Comment