Hello. I have an assignment that is completed minus one thing, I can\'t get the
ID: 3787249 • Letter: H
Question
Hello. I have an assignment that is completed minus one thing, I can't get the resize method in Circle class to actually resize the circle in my TestCircle claass. Can someone look and fix it? I would appreciate it! If you dont mind leaving acomment either in the answer or just // in the code on what I'm doing wrong to cause it to not work. That's all I've got. Just a simple revision and edit to make the resize work. Thank you in advance! I have the 4 classes listed below. Point, TestPoint,Circle, and TestCircle
---Point.java---
public class Point {
private int X;
private int Y;
public Point(int Xcoord, int Ycoord) {
X = Xcoord;
Y = Ycoord;
}
public int getX() {
return X;
}
public void setX(int i) {
this.X = X;
}
public int getY() {
return Y;
}
public void setY(int i) {
this.Y = Y;
}
public String toString() {
return "(" + X + "," + Y + ")";
}
}
---TestPoint.java---
public class TestPoint {
public static void main(String[] args) {
Point p = new Point (5,3);
System.out.println("TestPoint print: " + p);
}
}
---Circle.java---
public class Circle {
private double radius;
private Point p;
public Circle(int radius, int X, int Y) {
this.radius = radius;
this.p = new Point(X, Y);
}
public Point getPointInstance() {
return this.p;
}
public double area() {
double area = (3.14) * (radius) * (radius);
return area;
}
public void move(Point newCenter) {
p.setX(newCenter.getX());
p.setY(newCenter.getY());
}
public void resize(double resizeRate) {
radius = (radius * resizeRate);
}
}
---TestCircle.java---
public class TestCircle {
public static void main(String args[]) {
Circle c = new Circle(1, 0, 0);
Point p = c.getPointInstance();
System.out.println("Print TestCircle at origin: " + p);
double area = c.area();
System.out.println("Area of circle at origin: " + area);
Point newCenter = new Point(-3, 6);
c.move(newCenter);
c.resize(0.5);
System.out.println("New center: " + newCenter);
System.out.println("New circle area: " + area);
}
}
Explanation / Answer
-- > Only Change in TestCircle.java.When Call area Method .
public class TestCircle {
public static void main(String args[]) {
Circle c = new Circle(1, 0, 0);
Point p = c.getPointInstance();
System.out.println("Print TestCircle at origin: " + p);
double area = c.area();
System.out.println("Area of circle at origin: " + area);
Point newCenter = new Point(-3, 6);
c.move(newCenter);
c.resize(0.5);
System.out.println("New center: " + newCenter);
/* it must be specified with object of Circle class. In your code it take area value which is stored previously.*/
System.out.println("New circle area: " + c.area());
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.