
// Punkt.java


/******************************************************************************
/ Punkt.java modellerar en punkt.
/
/*****************************************************************************/

class Punkt
{
	// Klassvariabler -----------------
	public static final double    XMAX = Double.MAX_VALUE;
	public static final double    YMAX = Double.MAX_VALUE;
	public static final double    XMIN = Double.MIN_VALUE;
	public static final double    YMIN = Double.MIN_VALUE;
	
	
	// Instansvariabler ---------------
	private double    x;
	private double    y;
	
	
	// Konstruktorer ------------------
	public Punkt ()
	{
		x = 0;
		y = 0;
	}
	
	public Punkt (double x)
	{
		this.x = x;
		y = 0;
	}
	
	public Punkt (double x, double y)
	{
		this.x = x;
		this.y = y;
	}
	
	public Punkt (Punkt p)
	{
		this.x = p.x;
		this.y = p.y;
	}
	
	
	// Instansmetoder -----------------
	public double getX ()
	{
		return this.x;
	}
	
	public double getY ()
	{
		return this.y;
	}
	
	public void setX (double x)
	{
		this.x = x;
	}
	
	public void setY (double y)
	{
		this.y = y;
	}
	
	public String toString ()
	{
		return "(" + x + "," + y + ")";
	}
	
	public double avstand ()
	{
		return Math.sqrt (x * x + y * y);
	}
	
	public double avstand (Punkt p)
	{
		return Math.sqrt ((p.x - this.x) * (p.x - this.x) + 
		                  (p.y - this.y) * (p.y - this.y));
	}
	
	
	// Klassmetoder -------------------
	public static Punkt getSlunmpPunkt ()
	{
		return new Punkt (Math.random () * 2 - 1, Math.random () * 2 - 1);
	}
	
}