/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package pointtest; /** * class Point represents a point in the 1st quadrant of the * Cartesian plane * @author jcmtiernan */ public class Point { private int x; private int y; private double distanceFromOrigin; private Integer quadrant = new Integer(1); public Point(int x, int y) { if (x >= 0) { this.x = x; this.quadrant = 1; } else {this.x = 0; } if (y>=0) {this.y = y; } else { this.y = 0;} } public Point(int x) { this.setX(x); this.y = 0; } public Point(int x, int y, Integer quadrant) { if (!this.setX(x)) { System.out.println("x value is not in 1st quadrant"); } this.setY(y); this.quadrant = quadrant; } public Point() { this.x = 0; this.y = 0; } public boolean setX(int x) { if (x >= 0) { this.x = x; return true; } else { this.x = 0; return false; } } public boolean setY(int y) { if (y >= 0) { this.y = y; return true; } else { this.y = 0; return false; } } public boolean setQuadrant(Integer quadrant) { if (((quadrant.compareTo(0) ) > 0) && ((quadrant.compareTo(5)) < 0)) { this.quadrant = quadrant; return true; } return false; } public int getX() { return x; } public int getY() { return y; } public Integer getQuadrant() { return quadrant; } private double calculateDistanceFromOrigin() { //sqrt of x*x + y*y distanceFromOrigin = Math.sqrt(x*x + y*y); return distanceFromOrigin; } @Override public String toString() { return String.format("("+x+","+y+")"); } }