All pastes #25101 Raw Edit

void

public java v1 · immutable
#25101 ·published 2005-10-10 09:59 UTC
rendered paste body
import java.util.*;import java.lang.Math;interface Movable {	// Translate method 	public void Translate(double x, double y);}// Simple 2d point classclass 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 classclass 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 classpublic class lab01 {	public static void main(String[] args) {		// The vectors		Vector<Point> points = new Vector<Point>();		Vector<Circle> circles = new Vector<Circle>();		//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);					}}