Program name: Cube
Subject: IT134A_Computer Programming 3
Instructor: Mr. Dony Dongiapon
Date Started: Febuary 04,2009
Date Finished: Febuary 04,2009
Purpose: To create a class that will calculate the volume and area of a cube inside a private methods.
*/
import javax.swing.JOptionPane;
public class Cube{
private double vwidth;
private double vlength;
private double vheight;
private double vvolume;
private double varea;
public Cube(double width, double height, double length)
{
this.vwidth=width;
this.vheight=height;
this.vlength=length;
}
public Cube()
{
}
private double volume()
{
return (vwidth*vlength*vheight);
}
private double area()
{
return (vwidth*vlength);
}
public void setDimension(double newwidth, double newheight, double newlength)
{
this.vwidth=newwidth;
this.vheight=newheight;
this.vlength=newlength;
}
public String displayCube()
{
return String.format(volume()+" and "+area());
}
}
/* Programmer: Besas, Jhovan
Program name: CubeTester
Subject: IT134A_Computer Programming 3
Instructor: Mr. Dony Dongiapon
Date Started: Febuary 04,2009
Date Finished: Febuary 04,2009
Purpose: To create a CubeTester class that will access the private methods of the cube class.
*/
public class CubeTester{
public static void main(String args[]){
Cube Cubex=new Cube(2,8,4);
Cube Cubey=new Cube();
JOptionPane.showMessageDialog(null,"The volume and area having a parameter is: "+Cubex.displayCube(),
"Volume and Area of a Cube",JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null,"Lets proceed to the constructor without a parameter..");
String w=JOptionPane.showInputDialog("Kindly enter the value of width: ");
String h=JOptionPane.showInputDialog("Kindly enter the value of height: ");
String l=JOptionPane.showInputDialog("Kindly enter the value of lenght: ");
double h=Integer.parseInt(w);
double i=Integer.parseInt(h);
double j=Integer.parseInt(l);
Cubey.setDimension(h,i,j);
JOptionPane.showMessageDialog(null,"The volume and area having no a parameter is: "+Cubey.displayCube(),
"Volume and Area of a Cube",JOptionPane.PLAIN_MESSAGE);
}
}
No comments:
Post a Comment