Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *Circle class
- */
- public class Circle implements Comparable{
- private static final double PI = 3.14;
- private double radius;
- /**
- *constructor
- *pre: none
- *post: A Circle object created. Radius initialized to 1.
- */
- public Circle(){
- radius = 1;
- }
- public Circle(double r){
- radius = r;
- }
- public void setRadius(double newRadius){
- radius = newRadius;
- }
- public double getRadius(){
- return radius;
- }
- //....getRadius(), setRadius(), and other Circle class
- //methods
- /**
- *Determines if object c is smaller, the same,
- *or larger than this Circle object.
- *pre: c is a Circle object
- *post: -1 has been returned if c is larger than
- *this Circle, 0 has been returned if they are the same
- *size, and 1 has been returned if c is smaller than this Cirlce.
- */
- public int compareTo(Object c){
- Circle testCircle = (Circle) c;
- if(radius < testCircle.getRadius()){
- return (-1);
- }
- else if( radius == testCircle.getRadius()){
- return (0);
- }
- else{
- return (1);
- }
- }
- public String toString(){
- String str = "Circle with radius " + radius;
- return str;
- }
- public double area(){
- double area = 3.14 * radius * radius;
- return area;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement