public class Circle extends Shape { private double radius; private Point center;
ID: 3694173 • Letter: P
Question
public class Circle extends Shape {
private double radius;
private Point center;
public Circle(Point center, double radius) {
this.radius = radius;
this.center = center;
}
@Override
public double computeArea() {
return (Math.PI * Math.pow(radius, 2));
}
}
Extend this so that there is a concrete extension of Shape that contains the following public methods:
void moveCenter(Point P): changes the center to point P, radius remains unchanged
void changeRadius (double r): changes the value of the radius to r
Explanation / Answer
public class Circle extends Shape {
private double radius;
private Point center;
public Circle(Point center, double radius) {
this.radius = radius;
this.center = center;
}
@Override
public double computeArea() {
return (Math.PI * Math.pow(radius, 2));
}
public void moveCenter(Point P)
{
this.center = P;
}
public void changeRadius (double r)
{
this.radius=r;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.