I'm starting to see the issue of enum
in java and I have an exercise in which I'm asked to check which quadrant of the Cartesian plane are certain points, these points are stored in an ArrayList and the teacher told me to Through a enum
I could find out in which quadrant the point that is being analyzed could be and I could also tell if one of those points does not have a quadrant (one or two of the X and Y coordinates has a value of 0).
The problem is that I can not think of how to use enum
, someone to help me? I'm starting with that of la la poo.
I pass the classes:
package arraylist;
public class Punto {
private Double x;
private Double y;
public Punto(Double x, Double y) {
this.setX(x);
this.setY(y);
}
public Punto(Double xy) {
this(xy, xy);
}
public Punto() {
this(0.0);
}
public Double getX() {
return this.x;
}
public void setX(Double x) {
this.x = x;
}
public Double getY() {
return this.y;
}
public void setY(Double y) {
this.y = y;
}
public Double calcularDistancia(Punto punto) {
return Math.hypot(this.getX() - punto.getX(), this.getY() - punto.getY());
}
public String toString() {
return this.getX() + "," + this.getY();
}
public int getcuadrante() {
int cuadrante = 0;
if(x>0 && y>0) {
cuadrante = 1;
}
if(x<0 && y>0) {
cuadrante = 2;
}
if(x<0 && y<0) {
cuadrante = 3;
}
if(x>0 && y<0) {
cuadrante = 4;
}
return cuadrante;
}
}
package arraylist;
import java.util.ArrayList;
public class Plano {
private ArrayList<Punto> Puntos;
public ArrayList<Punto> getPuntos() {
return Puntos;
}
public Plano() {
this.setPuntos(new ArrayList<Punto>());
}
public void agregarPunto(Punto punto) {
this.getPuntos().add(punto);
}
public Integer getCantPuntos(Cuadrante cua) {
Integer cont = 0;
for(Punto punto: this.getPuntos()) {
if(punto.getcuadrante(cua.getX(),cua.getY()).equals(cua)) {
cont++;
}
return cont;
}
}
public void setPuntos(ArrayList<Punto> puntos) {
Puntos = puntos;
}
}
package arraylist;
import java.util.ArrayList;
public class UsoArrayList {
public static void main(String[] args ) {
ArrayList<Punto> vector = new ArrayList<Punto>();
System.out.println("Tamaño: " + vector.size());
}
}
What would be missing would be the enumerator, but I do not know how to implement it.