Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello. I have an assignment that is completed minus one thing, I can\'t get the

ID: 3787220 • 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 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 + ")";
   }

}

---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

Note:

What is the need of TestPoint here.And that to the TestPoint.java is also same as Point.java

No need of Testpoint.java file.If you want any clarifications just ask me.Thank You.

______________________

---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 + ")";
   }

}

Circle.java

public class Circle {
   private double radius;
private Point p;
public Circle(double 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+ (radius * resizeRate/100);

//Here the resize rate must in percentage so we have to divide with 100.and mutiply to the radius.That's the increase rate.Nest add to the original radius.

If we want to decrease provide negative rate.

}
}

___________________

---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: " + c.area()); //we have to call the method on the Circle class object.but you are displaying the variable value of old Circle area.

   }

}

______________________

Output:

Print TestCircle at origin: (0,0)
Area of circle at origin: 3.14
New center: (-3,6)
New circle area: 3.1714784999999996

______________Thank You