A demonstration of introductory object oriented programming. A class to define a circle object with radius, area, and perimeter parameters.
CircleClass
package circle;
public class CircleClass
{
// member variables
private double radius, circumference, area;
// constructor function
public CircleClass() { }
public CircleClass(double r) { setRadius(r); }
// accessors
public double getRadius() { return radius; }
public double getCircumference() { return circumference; }
public double getArea() { return area; }
// data modifiers
public void setRadius(double x)
{
radius = x;
circumference = 2 * Math.PI * radius;
area = Math.PI * radius * radius;
}
public void setCircumference(double x)
{
circumference = x;
radius = circumference / (2 * Math.PI);
area = Math.PI * radius * radius;
}
private void setArea(double x)
{
area = x;
radius = Math.sqrt(area / Math.PI);
circumference = 2 * Math.PI * radius;
}
}
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.