Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- public class Punto {
- public double x;
- public double y;
- public Punto(){
- this.x = 0;
- this.y = 0;
- }
- public Punto( double x, double y ){
- this.x = x;
- this.y = y;
- }
- public Punto( Punto otroPunto ){
- x = otroPunto.x;
- y = otroPunto.y;
- }
- public double distancia( Punto otroPunto ){
- double restaXCuadrado = Math.pow( x - otroPunto.x , 2 );
- double restaYCuadrado = Math.pow( y - otroPunto.y , 2 );
- return Math.pow( restaXCuadrado + restaYCuadrado, 0.5 );
- }
- public Punto puntoMedio( Punto otroPunto ){
- double medioX = ( x + otroPunto.x ) / 2.0;
- double medioY = ( y + otroPunto.y ) / 2.0;
- return new Punto( medioX, medioY );
- }
- public void translate( Punto otroPunto ){
- x = otroPunto.x;
- y = otroPunto.y;
- }
- public void translate( double x, double y ){
- this.x = x;
- this.y = y;
- }
- @Override
- public String toString(){
- return "( " + x + ", " + y + " )";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement