Can someone help me answer these questions (put in as comments throughout the co
ID: 3772119 • Letter: C
Question
Can someone help me answer these questions (put in as comments throughout the code)?
package lab;
/**
* Point class to represent a point on the display and the display size.
*
*
*/
public class Circle {
/**
* --Explain the purpose of this variable.
*/
private int x;
/**
* --Explain the purpose of this variable.
*/
private int y;
/**
* --Explain the purpose of this variable.
*/
private int size;
@SuppressWarnings("unused")
private Circle(){
}
/**
* Constructs a Point of radius 1.
* @param X the horizontal coordinate of the center of the point
* @param Y the vertical coordinate of the center of the point.
*/
public Circle(int X, int Y){
set(X, Y, 1);
}
/**
* Constructs a Point of radius s.
* @param X the horizontal coordinate of the center of the point
* @param Y the vertical coordinate of the center of the point.
* @param s the radius of the point.
*/
public Circle(int X, int Y, int s){
set(X, Y, s);
}
/**
* --Explain the purpose of this method.
*/
public int getX(){
return x;
}
/**
* --Explain the purpose of this method.
*/
public int getY(){
return y;
}
/**
* --Explain the purpose of this method.
*/
public int getSize(){
return size;
}
/**
* --Explain the purpose of this method. Explain each parameter.
*/
public void set(int X, int Y, int R){
x=X;
y=Y;
size=R;
}
/**
* --Explain the purpose of this method. Explain the parameter.
*/
public void setSize(int s){
size = s;
}
@Override
public String toString(){
return "Point: [(x:"+x+"), (y:"+y+"), (size:"+size+")]" ;
}
@Override
public boolean equals(Object obj){
if(obj instanceof Circle){
Circle parm = (Circle) obj;
return (parm.x==this.x)
&& (parm.y==this.y)
&& (parm.size==this.size);
}
else return false;
}
/**
* --Update the code for this method to compute the area of the circle
*/
public double area(){
return 0;
}
/**
* --Update the code for this method to determine if two circles overlap.
* --Why is this method static?
* --Return true if the circles overlap. Return false otherwise
*/
public static boolean intersect(Circle a, Circle b){
return false;
}
/**
* --Update the code for this method to determine if Circle b is completely
* enclosed in Circle a.
* --Why is this method static?
* --Return true if the circles enclose. Return false otherwise
*/
public static boolean enclose(Circle a, Circle b){
return false;
}
}
Explanation / Answer
// My code is in bold
package lab;
import java.util.Math;
/**
* Point class to represent a point on the display and the display size.
*
*
*/
public class Circle {
/**
* --Explain the purpose of this variable.
* This variable stores the X-coordinate of the center of the circle
*/
private int x;
/**
* --Explain the purpose of this variable.
* This variable stores the Y-coordinate of the center of the circle
*/
private int y;
/**
* --Explain the purpose of this variable.
* This variable stores the radius of the circle
*/
private int size;
@SuppressWarnings("unused")
private Circle(){
}
/**
* Constructs a Point of radius 1.
* @param X the horizontal coordinate of the center of the point
* @param Y the vertical coordinate of the center of the point.
*/
public Circle(int X, int Y){
set(X, Y, 1);
}
/**
* Constructs a Point of radius s.
* @param X the horizontal coordinate of the center of the point
* @param Y the vertical coordinate of the center of the point.
* @param s the radius of the point.
*/
public Circle(int X, int Y, int s){
set(X, Y, s);
}
/**
* --Explain the purpose of this method.
* getter method for X-coordinate
* returns X-coordinate of calling object
*/
public int getX(){
return x;
}
/**
* --Explain the purpose of this method.
* getter method for Y-coordinate
* returns Y-coordinate of calling object
*/
public int getY(){
return y;
}
/**
* --Explain the purpose of this method.
* getter method for radius of the circle
* returns radius of calling object
*/
public int getSize(){
return size;
}
/**
* --Explain the purpose of this method. Explain each parameter.
* Setter method for all class members
* sets x-coordinate to X, y-coordinate to Y and radius of the circle to R
*/
public void set(int X, int Y, int R){
x=X;
y=Y;
size=R;
}
/**
* --Explain the purpose of this method. Explain the parameter.
* setter method for radius
* sets the radius of teh calling object to s
*/
public void setSize(int s){
size = s;
}
@Override
public String toString(){
return "Point: [(x:"+x+"), (y:"+y+"), (size:"+size+")]" ;
}
@Override
public boolean equals(Object obj){
if(obj instanceof Circle){
Circle parm = (Circle) obj;
return (parm.x==this.x)
&& (parm.y==this.y)
&& (parm.size==this.size);
}
else return false;
}
/**
* --Update the code for this method to compute the area of the circle
*/
public double area(){
double area;
area = Math.PI*Math.pow(size,2);
return area;
}
/**
* --Update the code for this method to determine if two circles overlap.
* --Why is this method static?
* This method is called with two circle objects as parameters. So, it dont need a circle object to call. A function should be static if it has to be called from another static method(main) with out object.
* --Return true if the circles overlap. Return false otherwise
*/
public static boolean intersect(Circle a, Circle b){
/* if distance between the centers of two circles is less than sum of their radii,
then the two circles are considered overlapping.
*/
double distance;
distance = Math.sqrt(Math.pow(b.getX()-a.getX(),2) + Math.pow(b.getY()-a.getY(),2));
if(distance < a.getSize() + b.getSize())
return true;
return false;
}
/**
* --Update the code for this method to determine if Circle b is completely
* enclosed in Circle a.
* --Why is this method static?
* This method is called with two circle objects as parameters. So, it dont need a circle object to call. A function should be static if it has to be called from another static method(main) with out object.
* --Return true if the circles enclose. Return false otherwise
*/
public static boolean enclose(Circle a, Circle b){
/* if distance between the centers of two circles added to radius of circle b is lessthan radius of circle a,
then the circle b is considered enclosed in circle a.
*/
double distance;
distance = Math.sqrt(Math.pow(b.getX()-a.getX(),2) + Math.pow(b.getY()-a.getY(),2));
if(distance + b.getSize() > a.getSize())
return false;
return true;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.