if ur stl strunggling how to program a circle class here s my - TopicsExpress



          

if ur stl strunggling how to program a circle class here s my solution 1.package circleAndCylinder; public class Circle { private double radius; private String color; public double setRadius(){ return radius; } public void getRadius(double value) { if (radius < 0) radius = 0.00; radius = value; } public double getArea() { return radius* radius*Math.PI; } public double getCircumfarance() { return this.radius *Math.PI*2; } } // the following class is for cylinder 2.package circleAndCylinder; public class Cylinder extends Circle{ private double height; private double volume; public Cylinder(){ super(); height = 2.00; } public Cylinder( double radius , double height) { this .height = height; } public double getHeight(){ return height; } public double setVolume() { return super.getArea()*height; } public void getVolume( double x) { x = super.getArea()*height; // using circle area } public double getArea() { return super.getArea()*setRadius()*height; } } // this is test class 3.package circleAndCylinder; public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Circle info = new Circle(); // initialyse the value of radius info.getRadius(3.00); // printing the value of radius System.out.println("the characteristic of circle ar "); System.out.println("the radius is "+ info.setRadius()); // calculating the area System.out.println("the area of circler is "+ + info.getArea()); // calculating the circumfarancve of an area System.out.println( " the diameter is "+ info.getCircumfarance()); // extending the class of cylinder to an existing class of circle Cylinder kho = new Cylinder(); kho.getRadius(3.00); System.out.println("characteristic of a circle ar as follows "); // printing the heght cylinder System.out.println("height : "+kho.getHeight()); System.out.println("volume of "+kho.setVolume());// printing out the volume of a circle } } //S.Mabika
Posted on: Wed, 04 Sep 2013 14:47:15 +0000

Trending Topics



Recently Viewed Topics




© 2015