Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ex2;
- /**
- * Circle class
- *
- * @author Hi.Im.darkness
- */
- public class Circle extends Shape {
- /**
- * This is a constant variable of class
- * This is value of PI in mathimetic
- */
- private static final double PI = 3.14;
- /**
- * Radius of circle
- */
- private double radius;
- /**
- * Default Constructor
- */
- public Circle() {
- setRadius(1.0);
- }
- /**
- * Contructor arguments
- *
- * @param _radius double type
- */
- public Circle(double _radius) {
- setRadius(_radius);
- }
- /**
- * Constructor arguments
- *
- * @param _color String type
- * @param _filled boolean type
- * @param _radius double type
- */
- public Circle(double _radius, String _color, boolean _filled) {
- super(_color, _filled);
- setRadius(_radius);
- }
- /**
- * Set radius of circle
- *
- * @param _radius double type
- */
- public void setRadius(double _radius) {
- radius = _radius;
- }
- /**
- * Get radius of Circle
- *
- * @return double type
- */
- public double getRadius() {
- return radius;
- }
- /**
- * Compute and return area of Circle
- *
- * @return double type
- */
- public double getArea() {
- return PI * radius * radius;
- }
- /**
- * Compute and return perimeter of Circle
- *
- * @return double type
- */
- public double getPerimeter() {
- return PI * 2 * radius;
- }
- /**
- * {@inheritDoc}
- *
- * @return addition infomation about radius, area and perimeter of object
- */
- @Override
- public String toString() {
- String shapeStr = super.toString();
- String radiusStr = String.format("%-10s:%10s%n", "Radius", radius);
- String areaStr = String.format("%-10s:%10s%n", "Area", getArea());
- String perimeterStr = String.format("%-10s:%10s%n", "Perimeter", getPerimeter());
- return shapeStr + radiusStr + areaStr + perimeterStr;
- }
- public static void main(String[] args) {
- System.out.println(new Circle());
- System.out.println(new Circle(2));
- System.out.println(new Circle(2, "black", true));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement