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
I am not sure what I am doing wrong in this coding. I keep getting this...
I am not sure what I am doing wrong in this coding. I keep getting this error. I tried to change it to Circle2D.java but it still comes an error: Compiler error: class Circle2D is public, should be declared in a file named Circle2D.java public class Circle2D { public class Exercise10_11 { public static void main(String[] args) {     Circle2D c1 = new Circle2D(2, 2, 5.5);     System.out.println("area: " + c1.getArea());     System.out.println("perimeter: " + c1.getPerimeter());     System.out.println("contains(3, 3): "...
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...
How do I make this: public class Country {     private String name;     private double area;     private...
How do I make this: public class Country {     private String name;     private double area;     private int population;     public Country(String name, double area, int population) {         this.name = name;         this.area = area;         this.population = population;     }     public double getPopulationDensity() {         return population / area;     }     public String getName() {         return name;     }     public void setName(String name) {         this.name = name;     }     public double getArea() {         return area;     }     public void setArea(double area) {         this.area = area;     }     public int getPopulation()...
How do I get this portion of my List Iterator code to work? This is a...
How do I get this portion of my List Iterator code to work? This is a portion of the code in the AddressBookApp that I need to work. Currently it stops at Person not found and if it makes it to the else it gives me this Exception in thread "main" java.lang.NullPointerException    at AddressBookApp.main(AddressBookApp.java:36) iter.reset(); Person findPerson = iter.findLastname("Duck"); if (findPerson == null) System.out.println("Person not found."); else findPerson.displayEntry(); findPerson = iter.findLastname("Duck"); if (findPerson == null) { System.out.println("Person not found.");...
Write a Java class called Rectangle that represents a rectangular two-dimensional region. It should have following...
Write a Java class called Rectangle that represents a rectangular two-dimensional region. It should have following 4 fields: int x (x-coordinate for its top left corner) int y (y coordinate for its top left corner) double height (height of the rectangle) double width (width of the rectangle) Your rectangle objects should have the following methods: public Rectangle(int newx, int newy, int newwidth, int newheight) Constructor that initializes the x-coordinate, y-coordinate for the top left corner and its width and height....
I have a 2 class code and it works everything is fine and runs as it...
I have a 2 class code and it works everything is fine and runs as it supposed too. What will the UML be for both classes. Here's the code, any help will be awsome, Thanks. import java.util.Scanner; public class PayRollDemo { public static void main(String[] args) { double payRate; int hours; PayRoll pr = new PayRoll(); Scanner keyboard = new Scanner(System.in); for (int index = 0; index < 7 ; index++ ) { System.out.println(); System.out.println("EmployeeID:" + pr.getEmployeeID(index)); System.out.println(); System.out.println("Enter the...
This assignment is an individual assignment. For Questions 1-3: consider the following code: public class A...
This assignment is an individual assignment. For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B()...
Please solve this problem in java. import java.util.Arrays; public class PriorityQueue { /* This class is...
Please solve this problem in java. import java.util.Arrays; public class PriorityQueue { /* This class is finished for you. */ private static class Customer implements Comparable { private double donation; public Customer(double donation) { this.donation = donation; } public double getDonation() { return donation; } public void donate(double amount) { donation += amount; } public int compareTo(Customer other) { double diff = donation - other.donation; if (diff < 0) { return -1; } else if (diff > 0) { return...
(JAVA) I have "cannot be resolved or is not a field" error on node.right = y;...
(JAVA) I have "cannot be resolved or is not a field" error on node.right = y; and node.left = x; //BuildExpressionTree.java import java.util.*; import javax.swing.*; import javax.xml.soap.Node; public class BuildExpressionTree {    private Stack stack = new Stack();    private Node node;       public static boolean isOperator(String token){        if(token == "+" || token == "-" || token == "*" || token == "/"){            return true;        }        JOptionPane.showMessageDialog(null, "Invalid token" +...
<<<<<<<< I need only the UML diagram for ALL classes.Java???????????? public class House {    private...
<<<<<<<< I need only the UML diagram for ALL classes.Java???????????? public class House {    private int houseNumber;    private int bedrooms;    private int sqFeet;    private int year;    private int cost;    public House(int houseNumber,int bedrooms,int sqFeet, int year, int cost)    {        this.houseNumber = houseNumber;        this.bedrooms = bedrooms;        this.sqFeet = sqFeet;        this.year = year;        this.cost = cost;    }    public int getHouseNumber()    {        return houseNumber;    }   ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT