Program Title:Cube
Date:Feb 4, 2009
Purpose: To create a source code of a cube*/
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:Tomarocon.Rolando
Program Title:CubeTester
Date:Feb 4, 2009
Purpose: To test the cube*/
public static void main(String[] args){
Cube myCube1=new Cube(2,2,2);
myCube.displayCube();
cube myNewCube = new cube();
myNewCube.displayCube();
}
}
No comments:
Post a Comment