/**
* A simple class to store a point in 2D space with a label (name).
* @author Chuck Cusack
* @version 9/11/25
*/
public class Point
{
private int x;
private int y;
private String name;
/**
* Constructor for objects of class Point
*/
public Point()
{
x = 0;
y = 0;
name = "";
}
public Point(int xCoord, int yCoord, String itsName) {
x = xCoord;
y = yCoord;
name = itsName;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public String getName() {
return name;
}
public void setX(int newX) {
x = newX;
}
public void setY(int newY) {
y = newY;
}
public void setName(String newName) {
name = newName;
}
/**
* Return true if and only if both coordinates are multiples of 10.
*/
public boolean onTenGrid() {
if(x%10==0 && y%10==0) {
return true;
} else {
return false;
}
}
/**
* Alternative version of onTenGrid
*/
public boolean onTenGridV2() {
return x%10==0 && y%10==0;
}
/**
* Return which coordinate this point is in.
* Coordinate as follows:
* 2|1
* ___
* 3|4
* Return 0 if the point is on one of the axes
*/
public int getQuadrant() {
if(x==0 || y==0) {
return 0;
}
if(x>0) {
if(y>0) {
return 1;
} else {
return 4;
}
} else {
if(y>0) {
return 2;
} else {
return 3;
}
}
}
/**
* Alternative version of getQuadrant that uses logical operators instead of nested conditionals
*/
public int getQuadrantV2() {
if(x==0 || y==0) {
return 0;
}
if(x>0 && y>0) {
return 1;
} else if (x>0 && y<0) {
return 4;
} else if(x<0 && y>0) {
return 2;
} else {
return 3;
}
}
}