-
Notifications
You must be signed in to change notification settings - Fork 0
/
Circle.java
50 lines (45 loc) · 1.17 KB
/
Circle.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* CS2030S Lab 0: Circle.java
* Semester 2, 2022/23
*
* <p>The Circle class represents a circle with a center
* and a radius.
*
* @author XXX
*/
class Circle {
/** The center of the circle. */
private Point c;
/** The radius of the circle (assume positive). */
private double r;
/**
* Constructor for a circle. Takes in a center c and a
* radius r (assume to be positive).
*
* @param c The center of the new circle.
* @param r The radius of the new circle.
*/
public Circle(Point c, double r) {
this.c = c;
this.r = r;
}
/**
* Checks if a given point p is contained within the circle.
*
* @param p The point to test.
* @return true if p is within this circle; false otherwise.
*/
public boolean contains(Point p) {
// TODO
boolean checkContains = ((p.getX() - c.getX()) * (p.getX() - c.getX()) + (p.getY() - c.getY()) * (p.getY() - c.getY())) <= r * r;
return checkContains;
}
/**
* Return the string representation of this circle.
*
* @return The string representing of this circle.
*/
public String toString() {
return "{ center: " + this.c + ", radius: " + this.r + " }";
}
}