Wednesday, February 4, 2009

IT134A_DDS

/*Programmer:Cristine A. Salac
Date Started:02/04/09
Date Finished: 02/04/09
Program Name: Cube
Program 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:Cristine A. Salac
Date Started:02/04/09
Date Finished: 02/04/09
Program Name: CubeTester
Program Purpose: To create classes using Visibility Modifiers.
*/

import java.util.Scanner;class CubeTester{
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