Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CircleClient.java
- public class CircleClient {
- public static void main(String[] args) {
- Point p1 = new Point(10,5);
- Circle c1 = new Circle(p1,7);
- System.out.println(c1);
- System.out.println("Area: " + c1.getArea());
- System.out.println("Circumference: " + c1.getCircumference());
- Point p2 = new Point(5,7);
- if(c1.contains(p2 ))
- System.out.println("(" + p2 + ") lies within the circle");
- else
- System.out.println("(" + p2 + ") does not lie within the circle");
- }
- }
- Circle.java
- public class Circle {
- private int radius;
- public Point center;
- public Circle(Point center, int radius) {
- this.radius = radius;
- this.center = center;
- }
- public Point getCenter() {
- return center;
- }
- public int getRadius() {
- return radius;
- }
- public double getArea() {
- return (Math.PI * radius * radius);
- }
- public double getCircumference() {
- return (2 * Math.PI * radius);
- }
- public String toString() {
- return "Circle[center=(" + center + "), radius=" + radius + "]";
- }
- public boolean contains(Point p) {
- if(Point.distance(center, p) <= radius)
- return true;
- else
- return false;
- }
- }
- Point.java
- public class Point {
- private int xp;
- private int yp;
- public Point(int xp, int yp) {
- this.xp = xp;
- this.yp = yp;
- }
- public String toString() {
- return xp + "," + yp;
- }
- public static double distance(Point a, Point b) {
- return Math.sqrt((a.xp - b.xp)*(a.xp - b.xp) + (a.yp - b.yp)*(a.yp - b.yp));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment