I want to write a method that compares the attributes of two objects from the same class. Say I'v got point1 & point2 of the Point class, which have the attributes of:
public class Point{
private double x;
private double y;
private double z;
[...] */constructor and methods*/[...]
}
public static void main (String[] args){
Point point1 = new Point(5, 10, 20);
Point point2 = new Point(0, 5, 10);
}
I want to compare the x, y, and z values of point1 & point2 against each other but I have no idea how to do so. How would I differentiate between the different values in the code block of a method? This is the theoretical method I would write if I could:
public double comparePoints(Point a, Point b){
if (x1 < x2){
System.out.println("Point b has the bigger x-value");
return x2;
}
etc.
}
Any ideas how to do this?