date started:February 4,2009
date ended:February 4,2009
Programm name:Cube
Programm purpose:to learned more about visibility modifier
*/
public class Cube{
private double width;
private double length;
private double height;
private double volume;
private double area;
public Cube(double w,double h,double l)
{
width=w;
height=h;
length=l;
}
public Cube()
{
}
private double volume()
{
return(width*length*height);
}
private double area()
{
return (width*length);
}
public void Dimension(double nLength, double nHeight, double nWidth)
{
length=nLength;
width=nWidth;
height=nHeight;
}
public void displayCube()
{
System.out.println("The volume of the Cube:"+volume());
System.out.println("the area of the Cube:"+area());
}
}
CUBETESTER
/*programmer: Pacalioga, Mark Jay
date started:February 4,2009
date ended:February 4,2009
Programm name:Cube
Programm purpose:to learned more about visibility modifier
*/
import java.util.Scanner;
class CubeTester
{
public static void main(String args[])
{
double l;
double w;
double h;
System.out.println("the cube with a parameter");
Cube newCube=new Cube(1,2,3);;
newCube.displayCube();
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");
Cube secondCube=new Cube();
secondCube.Dimension(l,w,h);
secondCube.displayCube();
}
}
No comments:
Post a Comment