Question

Question 11 (20 points) Given the class Point below, define a class Circle that represent a circle with a given center and ra
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans 11

public class Circle
{
public float radius; //radius of type float
Point center; //center of type Point class

public Circle(float radius,Point center) //contructor for initilizing the variables
   {
   this.radius=radius;
   this.center=center;
   }

public String getCenter() //getting the data of the center
   {
   return center;
   }

public void setRadius(float r) //setting the value of the radius
   {
   radius=r;
   }

public boolean liesOnCircle() // checking the condition by calling the distance function from point class
   {
   if(Point.distance()==radius)
       return true;
   else
       return false;
   }

}

Ans 12

public class CircleTest
{
public static void main(String[] args)
{
public int count=0;
Scanner s=new Scanner(System.in); //using scanner to take input from the user

System.out.println("Let the center be (h,k) . Enter the "h" of the center ");

int arrCenterH[]=new int[50]; //taking 50 inputs for the first point of the center of the circle

for(int i=0;i<50;i++)
       {
arrCenterH[i]=s.nextInt();
       }
System.out.println("Let the center be (h,k) . Enter the "k" of the center ");

int arrCenterK[]=new int[50]; //taking 50 inputs for the first point of the center of the circle

for(int i=0;i<50;i++)
       {
arrCenterK[i]=s.nextInt();
       }

System.out.println("enter the data of the radius "); //storing the data of the address in yet another array

int arrRadius[]=new int[50];

for(int i=0;i<50;i++)
       {
arrRadius[i]=s.nextInt();
       }

public void ConditionCheck(int[] arrCenterH,int[] arrCenterK,Point p) //If the center lies on the circumfere,the count increases
   {
   for(int j=0;j<50;j++)
       {
       if(Math.pow(p.x-arrCenterH[j],2)+Math.pow(p.y=arrCenterK[j],2) == Math.pow(arrCenterH[j],2) + Math.pow(arrCenterK[j],2))
           {
           count++;
           }
       System.out.println(count); //Prints the number of circles passing through the center
}
}
}

Add a comment
Know the answer?
Add Answer to:
Question 11 (20 points) Given the class Point below, define a class Circle that represent a...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • public class Point f private int x; private int y; public Point(int x, int y) this.x...

    public class Point f private int x; private int y; public Point(int x, int y) this.x X; this.y y; public int getX() return x; public int getY() return Y: public double distance (Point other) double dx this.x-other.x; double dy this.y-other.y double dist Math.sqrt(dx dx + dy dy); return dist;

  • Hello! This is C++. Q3. Write a program Define a Super class named Point containing: An...

    Hello! This is C++. Q3. Write a program Define a Super class named Point containing: An instance variable named x of type int. An instance variable named y of type int. Declare a method named toString() Returns a string representation of the point. Constructor that accepts values of all data members as arguments. Define a Sub class named Circle. A Circle object stores a radius (double) and inherit the (x, y) coordinates of its center from its super class Point....

  • Java Help 2. Task: Create a client for the Point class. Be very thorough with your...

    Java Help 2. Task: Create a client for the Point class. Be very thorough with your testing (including invalid input) and have output similar to the sample output below: ---After declaration, constructors invoked--- Using toString(): First point is (0, 0) Second point is (7, 13) Third point is (7, 15) Second point (7, 13) lines up vertically with third point (7, 15) Second point (7, 13) doesn't line up horizontally with third point (7, 15) Enter the x-coordinate for first...

  • Can you tell me if this is right please import java.lang.reflect.AnnotatedArrayType; /** * The class <b>Point</b>...

    Can you tell me if this is right please import java.lang.reflect.AnnotatedArrayType; /** * The class <b>Point</b> is a simple helper class that stares a 2 dimentional element on a grid * * @author Guy-Vincent Jourdan, University of Ottawa */ public class Point { public int dot, row, col;       // ADD YOUR INSTANCE VARIABLES HERE /**    * Constructor    *    * @param x    * the x coordinate    * @param y    * the y coordinate...

  • Using separate files, write the definition for a class called Point and a class called Circle. Th...

    Using separate files, write the definition for a class called Point and a class called Circle. The class point has the data members x (double) and y (double) for the x and y coordinates. The class has the following member functions: a) void set_x(double) to set the x data member b) void set_y(double) to set the y data member c) double get_x() to return the the x data member d) double get_y() to return the the y data member e)...

  • Exercise 2: There can be several constructors as long as they differ in number of parameters...

    Exercise 2: There can be several constructors as long as they differ in number of parameters or data type. Alter the program so that the user can enter just the radius, the radius and the center, or nothing at the time the object is defined. Whatever the user does NOT include (radius or center) must be initialized somewhere. There is no setRadius function and there will no longer be a setCenter function. You can continue to assume that the default...

  • Write a java class definition for a circle object. The object should be capable of setting...

    Write a java class definition for a circle object. The object should be capable of setting radius, and computing its area and circumference. Use this to create two Circle objects with radius 10 and 40.5, respectively. Print their areas and circumference. Here is the Java class file (Circle.java). Compile it. public class Circle{ //Instance Variables private double PI = 3.1459; private double radius; //Methods public Circle ( ) { }    //get method (Accessor Methods ) public double getRadius (...

  • QUESTION 7 10 points Save Answer Given is a java class 'lustrate'. What are the contents...

    QUESTION 7 10 points Save Answer Given is a java class 'lustrate'. What are the contents of the object 13 right after line 13 in the main method? publie class Illustrate publie atatie void main (Stringl argo private int x private static int y 0; public statie int count-0 public Illustrate0) 1. Illustrate 11 -new 1llustrate(3) 2. Illustrate 12·new Illustrate(5); Illustrate.incrementy public Illustrate(int a) 9. Illustrate.count 10 public Illustrate(Illustrate I) 12 13. Illustrate 13·new Illustrate(11); 14 15. Illustrate 14-13; 16....

  • Please answer with a Java code. Every circle has a center and a radius. Given the...

    Please answer with a Java code. Every circle has a center and a radius. Given the radius, we can determine the circle’s area and circumference. Given the center, we can determine its position in the x-y plane. The center of a circle is a point in the x-y plane. Design the class Circle that can store the radius and center of the circle. Because the center is a point in the x-y plane and you designed the class to capture...

  • A general shape class is shown below. Shape has a dimension. It also defines constructors, getters,...

    A general shape class is shown below. Shape has a dimension. It also defines constructors, getters, setters and a toString method. class Shape{ int dimension; public Shape(){} public Shape(int newDimension){ dimension = newDimension; } public int getDimension(){ return dimension; } public void setDimension(int newDimension){ dimension = newDimension; } public String toString(){ return "Shape has dimension "+dimension; } } a. Define classes Circle and Square, which inherit from Shape class. b. Both classes must have two constructors similar to Shape class....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT