Wednesday, February 4, 2009

// programmer:Wendel B. Bocong
// date started: February 4, 2009
// date ended: February 4, 2009
// Programme name: Cube Exercise
// programme purpose: Implementing Class Through Visibility Modifier in JAVA

import java.util.Scanner;
public class CubeTester{

  public static void main(String[] args) {
      
    double w;
    double e;
    double n;

      
      Cube myCube1 = new Cube(8,10,5);
      myCube1.displayCube();
    
    
    Scanner a=new Scanner(System.in);
    System.out.println("length:");
    w=a.nextDouble();

    Scanner b=new Scanner(System.in);
    System.out.println("height:");
    e=b.nextDouble();
    
    Scanner c=new Scanner(System.in);
    System.out.println("width:");
    n=c.nextDouble();

        Cube myCube2=new Cube();    
        myCube2.SetDimension(w,e,n);
        myCube2.displayCube();     
  }
   
}



// programmer:Wendel B. Bocong
// date started: February 4, 2009
// date ended: February 4, 2009
// Programme name: Cube Exercise
// programme purpose: Implementing Class Through Visibility Modifier in JAVA


public class Cube{

    private double length;
    private double width;
    private double heigth;
    private double volume;
    private double area;



    public Cube(double w, double e, double n)
    {
    length=w;
    heigth=e;
    width=n;
    }

    public Cube( )
    {

    }



  private double area()
  {
      return (width*length);  
  }




  private double volume()
  {
    return(length*width*heigth);
  }


    public void SetDimension (double newlen, double newhei, double newwid)
    {
     length=newlen;
     width=newwid;
     heigth=newhei;
    }


  public void displayCube()
  {
      System.out.println("the area of the cube is " +area());
      System.out.println("the volume of the cube is " +volume());
  }
}





No comments:

Post a Comment