Wednesday, February 4, 2009

Cube Solution

//ProgrammerName: Joan N. Dominguez
//ProgramName: Cube
//Purpose: To create a program that calculate the volume of an object cube
//Date: February 04, 2009 
//Subect: Computer Programming 3
//Instructor: Dony Dongiapon



import javax.swing.JOptionPane;

public class Cube{
    private double Volume;
    private double Length;
    private double Width;
    private double Height;
    private double Area;

public CubeSolution(double Width, double Height, double Lenght)
  {
  this.Width;
  this.Height;
  this.Lenght;
  }
  public Cube()
  {
   
  }  
public void SetDimension(double newWidth, double newHeight, double newLength)
  {
  this.Width = newWidth;
  this.Height = newHeight;
  this.Lenght = newLength;
  }  
private double Volume(){
  return Width * Lenght * Height;
}

private double Area(){
  return Width * Lenght;
}  
public void displayCube(){
  System.out.print(Volume() + " and " + Area());
}

}

}



//ProgrammerName: Joan N. Dominguez
//ProgramName: CubeTester
//Purpose: To create a cube tester that test the cube class
//Date: February 04, 2009 
//Subect: Computer Programming 3
//Instructor: Dony Dongiapon



import javax.swing.JOptionPane;

public class CubeTester{
    
    public static void main(String []args){
        Cube newCube1 = new Cube(10,10,10);
        Cube newCube2 = new Cube();
                    
JOptionPane.showMessageDialog("\t The volume and area of constructor having a parameter: " 
  + newCube1.displayCube(),"Volume and Area of a Cube",JOptionPane.INFORMATION_MESSAGE);

 String Width = JOptionPane.showInputDialog(" Enter a value of Width "));
 String Height = JOptionPane.showInputDialog(" Enter a value of Height "));
 String Length = JOptionPane.showInputDialog(" Enter a value of Length "));  
     
 double x = Integer.parseInt(Width);
 double y = Integer.parseInt(Height);
 double z = Integer.parseInt(Length);
    
     
Cube2.setDimension(x, y, z);
JOptionPane.showMessageDialog("\t The volume and area of constructor having no a parameter is: " 
 + newCube2.displayCube(),"Volume and Area of a Cube",JOptionPane.INFORMATION_MESSAGE);
 
          }
    }
}

No comments:

Post a Comment