Advertisement
Guest User

MaisDistante

a guest
Aug 25th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. package aula2508;
  2.  
  3. import javax.swing.JOptionPane;
  4.  
  5. public class Ponto2D {
  6.    
  7.     double x, y;
  8.    
  9.     public void Print(int op) {
  10.        
  11.         if (op == 1){
  12.         JOptionPane.showMessageDialog(null, "Ponto A("+x+","+y+")");
  13.         }else{
  14.             JOptionPane.showMessageDialog(null, "Ponto B("+x+","+y+")");
  15.         }
  16.     }
  17.    
  18.     public double distanciaOrigem() {
  19.         double d;
  20.         d = Math.sqrt((x*x) + (y*y));
  21.         return d;
  22.     }
  23.  
  24.     public void setX(double i) {   
  25.     x = i; 
  26.     }
  27.  
  28.     public void setY(double i) {
  29.     y = i;
  30.     }
  31.    
  32.     public void deslocaEm(double a, double b) {
  33.         setX(x+a);
  34.         setY(y+b);
  35.     }
  36.    
  37.     /*public void maisDistante(Ponto2D P2){
  38.        
  39.         if(this.distanciaOrigem()>P2.distanciaOrigem()){
  40.            
  41.             this.Print(1);
  42.            
  43.         }else{
  44.            
  45.             P2.Print(0);
  46.            
  47.         }
  48.        
  49.     }*/
  50.    
  51. }
  52.  
  53.  
  54. ================================================================================================
  55.  
  56.  
  57. package aula2508;
  58.  
  59. import java.awt.event.InputEvent;
  60. import java.awt.im.spi.InputMethod;
  61.  
  62. import javax.swing.JOptionPane;
  63.  
  64. public class TestePonto2D {
  65.     public static void main (String[]args){
  66.        
  67.         Ponto2D A = new Ponto2D();
  68.         Ponto2D B = new Ponto2D();
  69.         //Ponto2D P2 = new Ponto2D();
  70.        
  71.         A.setX(4);
  72.         A.setY(0);
  73.         B.setX(5);
  74.         B.setY(0);
  75.        
  76.         A.deslocaEm(20, 40);
  77.         B.deslocaEm(10, 60);
  78.        
  79.         A.Print(1);
  80.         B.Print(0);
  81.        
  82.        
  83.     JOptionPane.showMessageDialog(null, "Distância de A: " + A.distanciaOrigem());
  84.     JOptionPane.showMessageDialog(null, "Distância de B: " + B.distanciaOrigem());
  85.    
  86.     maisDistante(A);
  87.    
  88.    
  89.        
  90.     }
  91.  
  92.     private void maisDistante(Ponto2D P2) {
  93.        
  94. if(this.distanciaOrigem()>P2.distanciaOrigem()){
  95.            
  96.             this.Print(1);
  97.            
  98.         }else{
  99.            
  100.             P2.Print(0);
  101.            
  102.         }
  103.        
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement