Question

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

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

}

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
This is the java code that I have, but i cannot get the output that I...
This is the java code that I have, but i cannot get the output that I want out of it. i want my output to print the full String Form i stead of just the first letter, and and also print what character is at the specific index instead of leaving it empty. and at the end for Replaced String i want to print both string form one and two with the replaced letters instead if just printing the first...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){    strName = " ";    strSalary = "$0";    } public Employee(String Name, String Salary){    strName = Name;    strSalary = Salary;    } public void setName(String Name){    strName = Name;    } public void setSalary(String Salary){    strSalary = Salary;    } public String getName(){    return strName;    } public String getSalary(){    return strSalary;    } public String...
Whenever I try to run this program a window appears with Class not Found in Main...
Whenever I try to run this program a window appears with Class not Found in Main project. Thanks in Advance. * * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Assignment10; /** * * @author goodf */ public class Assignment10{ public class SimpleGeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated;    /**...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have...
I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have this much public class Main { int WIDTH = 0; double HEIGHT = 0; public static void drawSmileyFaces() { System.out.println(" :-):-):-):-):-):-)"); } public static void main (String[] args) { for (int WIDTH = 0; WIDTH < 3; WIDTH++ ) { for(double HEIGHT = 0; HEIGHT < 2; HEIGHT++) { drawSmileyFaces(); } } } } I am pretty sure that alot of this is wrong...
I am a beginner when it comes to java codeing. Is there anyway this code can...
I am a beginner when it comes to java codeing. Is there anyway this code can be simplified for someone who isn't as advanced in coding? public class Stock { //fields private String name; private String symbol; private double price; //3 args constructor public Stock(String name, String symbol, double price) { this.name = name; this.symbol = symbol; setPrice(price); } //all getters and setters /** * * @return stock name */ public String getName() { return name; } /** * set...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
IN C++ - most of this is done it's just missing the bolded part... Write a...
IN C++ - most of this is done it's just missing the bolded part... Write a program that creates a class hierarchy for simple geometry. Start with a Point class to hold x and y values of a point. Overload the << operator to print point values, and the + and – operators to add and subtract point coordinates (Hint: keep x and y separate in the calculation). Create a pure abstract base class Shape, which will form the basis...
java Consider the following class definition: public class Circle { private double radius; public Circle (double...
java Consider the following class definition: public class Circle { private double radius; public Circle (double r) { radius = r ; } public double getArea(){ return Math.PI * radius * radius; } public double getRadius(){ return radius; } } a) Write a toString method for this class. The method should return a string containing the radius and area of the circle; For example “The area of a circle with radius 2.0 is 12.1.” b) Writeaequalsmethodforthisclass.ThemethodshouldacceptaCircleobjectasan argument. It should return...
Here is my java code, I keep getting this error and I do not know how...
Here is my java code, I keep getting this error and I do not know how to fix it: PigLatin.java:3: error: class Main is public, should be declared in a file named Main.java public class Main { ^ import java.io.*; public class Main { private static BufferedReader buf = new BufferedReader( new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { String english = getString(); String translated = translate(english); System.out.println(translated); } private static String translate(String s) { String latin =...