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 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.");...
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...
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...
<<<<<<<< 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;    }   ...
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;...
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...
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;    /**...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT