Advertisement
KaiserRego

G5E3Punto [Implementando objeto java.awt.Point]

Oct 2nd, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. public class G5E3Punto{
  2.    
  3.     java.awt.Point punto;
  4.    
  5.     /* pre: puntoInicial es un objeto de tipo java.awt.Point. Para crear un objeto tipo java.awt.Point:
  6.      * java.awt.Point ejemploDePunto = new java.awt.Point (10, 10)
  7.      * post: inicializa el punto con el puntoInicial pasado como parámetro. */
  8.     public G5E3Punto (java.awt.Point puntoInicial){
  9.        
  10.         punto = new java.awt.Point(puntoInicial);
  11.  
  12.     }
  13.    
  14.     public java.awt.Point consultarCoordenadas(){
  15.        
  16.         return (punto);
  17.     }
  18.    
  19.     public void cambiarCoordenadas (int nuevaCoordenadaX, int nuevaCoordenadaY){
  20.        
  21.         punto.x = nuevaCoordenadaX;
  22.         punto.y = nuevaCoordenadaY;
  23.     }
  24.    
  25.     public boolean estaEnElEjeX(){
  26.        
  27.         return (punto.getY() == 0);
  28.     }
  29.    
  30.     public boolean estaEnElEjeY(){
  31.        
  32.         return (punto.getX() == 0);
  33.     }
  34.    
  35.     public boolean estaEnElEjeDeCoordenadas(){
  36.        
  37.         return (punto.getX() == 0 && punto.getY() == 0);
  38.     }
  39.  
  40. }
  41.  
  42. /* Ejecución:
  43. Welcome to DrJava.
  44. > java.awt.Point miPuntoDeEjemplo = new java.awt.Point (10, 10)
  45. > G5E3Punto ejecucion = new G5E3Punto (miPuntoDeEjemplo)
  46. > ejecucion.consultarCoordenadas()
  47. java.awt.Point[x=10,y=10]
  48. > ejecucion.estaEnElEjeX()
  49. false
  50. > ejecucion.estaEnElEjeY()
  51. false
  52. > ejecucion.estaEnElEjeDeCoordenadas()
  53. false
  54. > ejecucion.cambiarCoordenadas (1, 0)
  55. > ejecucion.consultarCoordenadas()
  56. java.awt.Point[x=1,y=0]
  57. > ejecucion.estaEnElEjeX()
  58. true
  59. > ejecucion.estaEnElEjeY()
  60. false
  61. > ejecucion.cambiarCoordenadas (0, 0)
  62. > ejecucion.consultarCoordenadas()
  63. java.awt.Point[x=0,y=0]
  64. > ejecucion.estaEnElEjeDeCoordenadas()
  65. true
  66. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement