Advertisement
Guest User

Untitled

a guest
May 5th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.72 KB | None | 0 0
  1. package geometria;
  2.  
  3. import static java.lang.Math.sqrt;
  4.  
  5. public class Punkt {
  6.    //pola
  7.     double x;
  8.     double y;
  9.     private double sqrt;
  10.    
  11.     //konstruktor
  12.     public Punkt(){}
  13.    
  14.     public Punkt(double x, double y){
  15.         this.x=x;
  16.         this.y=y;
  17.     }
  18.     public double x() {
  19.         return x;
  20.     }
  21.     public double y() {
  22.         return y;
  23.     }
  24.     public void translate(double dx, double dy) {
  25.         x += dx;
  26.         y += dy;  
  27.     }
  28. //metody
  29. public double odloscOd0()
  30. {
  31.     return sqrt((x-0)*(x-0)+(y-0)*(y-0));      
  32. }
  33. public void jestSymetrycznyWzgl0(Punkt p)
  34. {
  35.     p.x = -p.x;
  36.     p.y = -p.y;
  37.    
  38. }
  39. public double odlegloscOdPunktu(Punkt p1, Punkt p2)
  40. {
  41.         return sqrt = sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
  42. }
  43. public void lezyWCwiartce(Punkt p)
  44. {
  45.     if(p.x>0&p.y>0)
  46.     {
  47.         System.out.println("I cwiartka");
  48.     }
  49.     else
  50.     {
  51.         if(p.x<0&p.y>0)
  52.         {
  53.             System.out.println("II cwiartka");
  54.         }
  55.         else
  56.         {
  57.             if(p.x<0&p.y<0)
  58.             {
  59.                 System.out.println("III cwiartka");
  60.             }
  61.             else
  62.             {
  63.                 if(p.x>0&p.y<0)
  64.                 {
  65.                     System.out.println("IV cwiartka");
  66.                 }
  67.             }
  68.         }
  69.     }
  70. }
  71. public void przesunOwektor(double a, double b){
  72.      x+=a;
  73.      y+=b;
  74.  }
  75.     @Override
  76.     public String toString() {
  77.         return ("(" + x + "," + y + ")");
  78.     }
  79. }
  80.  
  81. //klasa Odcinek
  82. package geometria;
  83.  
  84. import static java.lang.Math.sqrt;
  85.  
  86. public class Odcinek extends Punkt {
  87.     private Punkt s;
  88.     private Punkt k;
  89.     private Object p1;
  90.     private Object p2;
  91.     private String x1;
  92.     private String y1;
  93.     private String x2;
  94.     private String y2;
  95.    
  96.    
  97.    
  98.     //konstruktor
  99.     public Odcinek(Punkt s, Punkt k){
  100.         this.s=s;
  101.         this.k=k;
  102.     }
  103.     public Punkt getPoczatek() {
  104.         return s;
  105.     }
  106.     public void setStart(Punkt s) {
  107.         this.s = s;
  108.     }
  109.     public Punkt getKoniec() {
  110.         return k;
  111.     }
  112.     public void setKoniec(Punkt k) {
  113.         this.k = k;
  114.     }
  115.      public Odcinek (double x1, double y1, double x2, double y2)
  116.  {
  117.         Punkt P1 = new Punkt (x1,y1);
  118.         Punkt P2 = new Punkt (x2,y2);
  119.  }
  120.      public double dlugosc(Punkt p1, Punkt p2) {
  121.          return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
  122.     }
  123.     @Override
  124.     public void przesunOwektor(double a, double b){
  125.      x+=a;
  126.      y+=b;
  127.  }
  128.     @Override
  129.     public String toString() {
  130.         return ("[(" + x1 + "," + y1 + ")]" + "[(" + x2 + "," + y2 + ")]");
  131.     }
  132. }
  133.  // main
  134. package geometria;
  135.  
  136.  
  137. public class TestGeometria {
  138.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement