Wednesday, February 4, 2009

Cube Manipulation

/*Programmer:Rosedil Mae Mobreros
Program Title:Cube
Date:February 4, 2009
Purpose: To display different Cube manipulation by generating it's volume and area.*/

public class Cube{

private double cubewidth;
private double cubelength;
private double cubeheight;
private double cubevolume;
private double cubearea;




public Cube(double width, double height, double length)
{
this.cubewidth=width;
this.cubeheight=height;
this.cubelength=length;
}

public Cube()
{

}

private double volume()
{

return (cubewidth*cubelength*cubeheight);

}


private double area()
{

return (cubewidth*cubelength);

}

public void setDimension(double newwidth, double newheight, double newlength)
{
this.cubewidth=newwidth;
this.cubeheight=newheight;
this.cubelength=newlength;
}

public String displayCube()
{
return String.format(volume()+" and "+area());

}
}


/*Programmer:Rosedil Mae Mobreros
Program Title:CubeTester
Date:February 4, 2009
Purpose: To test the different Cube manipulation by generating it's volume and area.*/

import java.util.Scanner;

public class CubeTester1{

public static void main(String args[]){
Scanner scan=new Scanner(System.in);
Cube myCube1=new Cube(3,3,3);
Cube myCube2=new Cube();

System.out.println("The volume and area of a cube with width, height, and length is equal to 3: "+myCube1.displayCube());
System.out.print("Enter width value: ");
double w=scan.nextDouble();
System.out.print("Enter height value: ");
double h=scan.nextDouble();
System.out.print("Enter length value: ");
double l=scan.nextDouble();

myCube2.setDimension(w,h,l);
System.out.println("The volume and area of a cube with width, height, and length is being entered by the user are : "+myCube2.displayCube());


}
}

No comments:

Post a Comment