Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Write a program to calculate Cylinder area

  1. /*
  2.  * Write a program to calculate Cylinder area. Program should have class called
  3.  * Cylinder with radius and height as member variables and getArea member method.
  4.  * getArea method should print area of the Cylinder object.
  5.  */
  6.  
  7. class Cylinder{
  8.  
  9.  int r;
  10.  int h;
  11.  
  12.  void setData(int x, int y){
  13.   r = x;
  14.   h = y;
  15.  }
  16.  
  17.  void getArea(){
  18.  
  19.   //total area of cylinder is  = (2 * pi * r * r) + (2 * pi * r * h)
  20.   System.out.println("Area of Cylinder: " + (2* 3.14f * r * r) + (2* 3.14f * r * h));
  21.  }
  22. }
  23.  
  24. public class CylinderArea
  25. {
  26.  public static void main(String args[]){
  27.  
  28.   Cylinder c1 = new Cylinder();
  29.   c1.setData(10, 4);
  30.   c1.getArea();
  31.  
  32.   Cylinder c2 = new Cylinder();
  33.   c2.setData(3,4);
  34.   c2.getArea();
  35.  }
  36. }
Your rating: None Average: 5 (2 votes)
Share this
Anonymous's picture

Hi, This is

Hi, This is kiruba.Anyway super program. Thanks & Regards, Kiruba.V

Post new comment

2 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.