Hi,
I'm a newbie in programming, trying to work on a practice problem in classes and objects. I tried the following to construct Point of type double, but when I print Point C, it prints 0,0; can someone take a look and guide where I'm getting this wrong..
thanks,
upad
-----------------------------------------------------------------------------------
public class Point { private int x; private int y; private double a; private double b; //constructs a new point with (0,0) as coordinates public Point() { x=0; y=0; } //constructs a new point with the given (x,y) location public Point(int initialX, int initialY) { x = initialX; y = initialY; } //constructs a new point with coordinates of type double public Point(double initialX, double initialY) { if((initialX-(int) initialX)>0.5) a=(int)initialX + 1; //else // initialX=initialX; if((initialY-(int) initialY)>0.5) b=(int)initialY + 1; //else // initialY=initialY; } //returns the x-coordinate of this point int getX() { return x; } //returns the y-coordinate of this point public int getY() { return y; } } --------------------------------------------- public class ReferenceMystery3 { public static void main(String[] args) { double x = 3.1; double y = 3.9; Point A = new Point(); Point B = new Point(3,6); Point C = new Point(x,y); System.out.println(A); System.out.println(B); System.out.println(C); } } ------------------------------------------------ Output: (0,0) (3,6) (0,0)