Skip to content

Instantly share code, notes, and snippets.

@addicted2sounds
Created February 27, 2016 06:18
Show Gist options
  • Select an option

  • Save addicted2sounds/c932b7f97f9b086c55b6 to your computer and use it in GitHub Desktop.

Select an option

Save addicted2sounds/c932b7f97f9b086c55b6 to your computer and use it in GitHub Desktop.
package com.company;
/**
* Created by addicted on 27.02.16.
*/
public class Circle {
private double radius;
public double getCircumference() {
return 2 * Math.PI * radius;
}
public void setCircumference(double circumference) {
this.radius = circumference / (2 * Math.PI) ;
}
public Circle(double radius) {
this.radius = radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) throws IllegalArgumentException {
if (radius < 0) {
throw new IllegalArgumentException("Radius can't be negative");
}
this.radius = radius;
}
public double getArea() {
double area = Math.PI * Math.pow(radius, 2);
return area;
}
public void setArea(double area) throws IllegalArgumentException {
if (area < 0) {
throw new IllegalArgumentException("Area can't be negative");
}
radius = Math.sqrt(area / Math.PI);
}
public void print() {
System.out.println("I'm a circle");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment