Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class G5E3Punto{
- java.awt.Point punto;
- /* pre: puntoInicial es un objeto de tipo java.awt.Point. Para crear un objeto tipo java.awt.Point:
- * java.awt.Point ejemploDePunto = new java.awt.Point (10, 10)
- * post: inicializa el punto con el puntoInicial pasado como parámetro. */
- public G5E3Punto (java.awt.Point puntoInicial){
- punto = new java.awt.Point(puntoInicial);
- }
- public java.awt.Point consultarCoordenadas(){
- return (punto);
- }
- public void cambiarCoordenadas (int nuevaCoordenadaX, int nuevaCoordenadaY){
- punto.x = nuevaCoordenadaX;
- punto.y = nuevaCoordenadaY;
- }
- public boolean estaEnElEjeX(){
- return (punto.getY() == 0);
- }
- public boolean estaEnElEjeY(){
- return (punto.getX() == 0);
- }
- public boolean estaEnElEjeDeCoordenadas(){
- return (punto.getX() == 0 && punto.getY() == 0);
- }
- }
- /* Ejecución:
- Welcome to DrJava.
- > java.awt.Point miPuntoDeEjemplo = new java.awt.Point (10, 10)
- > G5E3Punto ejecucion = new G5E3Punto (miPuntoDeEjemplo)
- > ejecucion.consultarCoordenadas()
- java.awt.Point[x=10,y=10]
- > ejecucion.estaEnElEjeX()
- false
- > ejecucion.estaEnElEjeY()
- false
- > ejecucion.estaEnElEjeDeCoordenadas()
- false
- > ejecucion.cambiarCoordenadas (1, 0)
- > ejecucion.consultarCoordenadas()
- java.awt.Point[x=1,y=0]
- > ejecucion.estaEnElEjeX()
- true
- > ejecucion.estaEnElEjeY()
- false
- > ejecucion.cambiarCoordenadas (0, 0)
- > ejecucion.consultarCoordenadas()
- java.awt.Point[x=0,y=0]
- > ejecucion.estaEnElEjeDeCoordenadas()
- true
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement