Advertisement
Victoralm

Ponto2d

Feb 26th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. /*
  2.  * Solução para a pegadinha "Ponto2d" dos professores
  3.  * IPCA: São 2 arquivos
  4. */
  5. // Ponto2d.java
  6. public class Ponto2d {
  7.     private int x;
  8.     private int y;
  9.    
  10.     public Ponto2d(int a, int b) { // Construtor Ponto2d
  11.         this.setX(a);
  12.         this.setY(b);
  13.     }
  14.    
  15.     public double distancia(Ponto2d p) { // método distancia
  16. //      double distX = p.x - x;
  17. //      double distY = p.y - y;
  18.         double distX = p.x;
  19.         double distY = p.y;
  20.         return Math.sqrt(distX*distX + distY*distY);
  21.     }
  22.    
  23.     public int getX(){
  24.         return x;
  25.     }
  26.     public void setX(int x) {
  27.         this.x = x;
  28.     }
  29.     public int getY(){
  30.         return y;
  31.     }
  32.     public void setY(int y) {
  33.         this.y = y;
  34.     }
  35. }
  36.  
  37. // ImplP2d.java
  38. public class ImplP2d {
  39.  
  40.     public static void main(String[] args) {
  41.        
  42.         Ponto2d p = new Ponto2d(9, 7);
  43.        
  44.         System.out.println(p.getX());
  45.         System.out.println(p.getY());
  46.        
  47.         System.out.println(p.distancia(p));
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement