I have a class (Point2D), and an instance variable (double tav) in this class.
I would like to compare different Point2D objects (based on variable "tav") by the relational operators (<,>).
(a < b) means that (a.tav < b.tav).
Is there any way to solve this problem?
public class Point2D
{
private int x;
private int y;
private double tav;
Point2D()
{
this.x=Integer.parseInt(JOptionPane.showInputDialog("x"));
this.y=Integer.parseInt(JOptionPane.showInputDialog("y"));
tav = Math.sqrt(Math.pow(x,2) + Math.pow(y,2));
}
}
public class Hf2
{
public static void main(String[] args)
{
Pont2D a = new Pont2D();
Pont2D b = new Pont2D();
if(a<b) //It is wrong, I would like to solve this.
{
System.out.println("Bigger");
}
}
}