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...
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.");...
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...
Which method is correct to access the value of count? public class Person { private String...
Which method is correct to access the value of count? public class Person { private String name; private int age; private static int count = 0; } A. private int getCount() {return (static)count;} B. public static int getCount() {return count;} C. public int getCount() {return static count;} D. private static int getCount() {return count;} How can you print the value of count? public class Person { private String name; private int age; private static int count=0; public Person(String a, int...
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....
Assignment 1 - ITSC 2214 I have to complete the array list for a shopping list...
Assignment 1 - ITSC 2214 I have to complete the array list for a shopping list code and can't figure out how to complete it: Below is the code Complete the three empty methods (remove(), find(), and contains()) in the ShoppingListArrayList.java file. These methods are already implemented in the ShoppingListArray class. /////////////////////////////////////////////////////////////////////////////////////////////////////////// Grocery Class (If this helps) package Shopping; public class Grocery implements Comparable<Grocery> { private String name; private String category; private int aisle; private float price; private int quantity;...
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...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields,...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields...