import java.util.*; import java.lang.Math; interface Movable { // Translate method public void Translate(double x, double y); } // Simple 2d point class class Point implements Movable { // The coordinates double x,y; // Translate method implementation public void Translate(double x, double y) { this.x += x; this.y += y; } // Constructors Point(double x, double y) { this.x = x; this.y = y; } Point() { // random position values this.x = Math.random()*10; this.y = Math.random()*10; } // To String method for eye candy public String toString() { // Returns "Point:(this.x;this.y)" return new String(String.format("Point:(%g;%g)",this.x, this.y)); } } // A simple circle class class Circle extends Point { // inherits x,y from Point // r is the radius double r; // Constructors Circle(double x, double y, double r){ super(x,y); this.r = r; } Circle(double r) { super(); this.r = r; } Circle() { super(); this.r = Math.random(); } // To string eye candy :) public String toString() { // Returns "Cricle:(this.x;this.y,this.r)" return new String(String.format("Circle:(%g;%g;%g)",this.x, this.y,this.r)); } // Method checks wheter a point is inside this circle public boolean PointInside(Point v) { return (r*r >= (this.x-v.x)*(this.x-v.x)+(this.y-v.y)*(this.y-v.y))? true: false; } } // main class public class lab01 { public static void main(String[] args) { // The vectors Vector points = new Vector(); Vector circles = new Vector(); //Adding 100 elements for (int i = 0; i < 100; i++) { points.add(new Point()); circles.add(new Circle()); } // Checking for (Circle c : circles) for (Point p : points) if (c.PointInside(p)) System.out.println(p+" is in "+c); } }