/**
* AI: Francisco Lara-Dammer
* Lab 5
* Complete the code in the class Circle so that this program can run.
*/
public class Lab5{
public static void main(String[] args){
Circle c1 = new Circle();
Circle c2 = new Circle(1,1,3);
c1.printCircle();//Should print (0,0,1)
c2.printCircle();//Should print (1,1,3)
System.out.println("The area of your circle is " + c1.area());//Should print 3.14...
c1.expand(2);
c1.printCircle();//Should print (0,0,2)
System.out.println("There are " + Circle.getNumberOfCircles() + " thus far.");
//Should print 2.
}
}
class Circle{
double x;
double y;
double radius;
final static double pi = Math.PI;
static int count = 0;
//Constructs the circle with center in the origen and radious 1.
Circle(){
this.x = 0;
this.y = 0;
this.radius = 1;
count++;
}
//Constructs a circle with center (u, v) and radius r.
Circle(double u, double v, double r){
this.x = u;
this.y = v;
this.radius = r;
count++;
}
//Returns the Center (You may need to use the class Point).
Point getCenter(){
return new Point(this.x, this.y);
}
//Return the radius
double getRadius(){
return this.radius;
}
//Calculate the area of the circle. (pi*radius^2)
double area(){
return pi*this.radius*this.radius;
}
//The radius of this circle will be e times the original radius
void expand(double e){
this.radius = this.radius*e;
}
//Prints x, y and r as (x, y, r).
void printCircle(){
System.out.println("("+this.x + ", " + this.y + ", " + this.radius + ")");
}
//Define here your method getNumberOfCircles
static int getNumberOfCircles(){
return count;
}
}