Advertisement
cotolonco

Ejemplo Clase Punto

Aug 26th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package test;
  2.  
  3. public class Punto {
  4.    
  5.     public double x;
  6.     public double y;
  7.    
  8.     public Punto(){
  9.         this.x = 0;
  10.         this.y = 0;
  11.     }
  12.    
  13.     public Punto( double x, double y ){
  14.         this.x = x;
  15.         this.y = y;
  16.     }
  17.    
  18.     public Punto( Punto otroPunto ){
  19.         x = otroPunto.x;
  20.         y = otroPunto.y;
  21.     }
  22.    
  23.     public double distancia( Punto otroPunto ){
  24.         double restaXCuadrado = Math.pow( x - otroPunto.x , 2 );
  25.         double restaYCuadrado = Math.pow( y - otroPunto.y , 2 );
  26.         return Math.pow( restaXCuadrado + restaYCuadrado, 0.5 );
  27.     }
  28.    
  29.     public Punto puntoMedio( Punto otroPunto ){
  30.         double medioX = ( x + otroPunto.x ) / 2.0;
  31.         double medioY = ( y + otroPunto.y ) / 2.0;
  32.         return new Punto( medioX, medioY );
  33.     }
  34.    
  35.     public void translate( Punto otroPunto ){
  36.         x = otroPunto.x;
  37.         y = otroPunto.y;
  38.     }
  39.    
  40.     public void translate( double x, double y ){
  41.         this.x = x;
  42.         this.y = y;
  43.     }
  44.    
  45.     @Override
  46.     public String toString(){
  47.         return "( " + x + ", " + y + " )";
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement