Advertisement
rupek1995

PROSTOKATY JAVA ZIOMEK

Mar 16th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. package figury;
  2.  
  3. public class Prostokat {
  4.     private int xA;
  5.     private int yA;
  6.     private int xB;
  7.     private int yB;
  8.     private int xC;
  9.     private int yC;
  10.     private int xD;
  11.     private int yD;
  12.    
  13.     public Prostokat(int xA, int yA, int xB, int yB, int xC, int yC, int xD, int yD) {
  14.         this.xA = xA;
  15.         this.xB = xB;
  16.         this.xC = xC;
  17.         this.xD = xD;
  18.         this.yA = yA;
  19.         this.yB = yB;
  20.         this.yC = yC;
  21.         this.yD = yD;
  22.     }
  23.  
  24.     public Prostokat() {
  25.         this(0,0, 0,1, 1,1, 1,0);
  26.     }
  27.    
  28.     private double obliczOdcinek(int x1, int y1, int x2, int y2) {
  29.         return Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
  30.     }
  31.    
  32.     public double podajPole() {
  33.         double bok1;
  34.         double bok2;
  35.        
  36.         bok1 = obliczOdcinek(xA, yA, xB, yB);
  37.         bok2 = obliczOdcinek(xA, yA, xD, yD);
  38.        
  39.         return bok1*bok2;
  40.         }
  41.        
  42.         public void rysuj() {
  43.         System.out.println("PROSTOKAT:");
  44.         System.out.println("Wspolrzedne A: (" + xA + "," + yA + "); ");
  45.         System.out.println("Wspolrzedne B: (" + xB + "," + yB + "); ");
  46.         System.out.println("Wspolrzedne C: (" + xC + "," + yC + "); ");
  47.         System.out.println("Wspolrzedne D: (" + xD + "," + yD + "); ");
  48.         System.out.println("Dlugosc bokow: " + obliczOdcinek(xA,yA, xB,yB) + " oraz " + obliczOdcinek(xB,yB, xC,yC));
  49.         //Dokonczyc wspolrzedne oraz dl. bokow
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement