Advertisement
rupek1995

TROJKATY JAVA ZIOMEK

Mar 15th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. package figury;
  2.  
  3.  
  4. public class Trojkat {
  5.    
  6.     private double xA,yA,xB,yB,xC,yC;
  7.     private double a = obliczBok(xA,yA,xB,yB);
  8.     private double b = obliczBok(xB,yB,xC,yC);
  9.     private double c = obliczBok(xA,yA,xC,yC);
  10.    
  11.     public Trojkat(double xA,double yA, double xB,double yB,double xC, double yC) {
  12.         this.xA = xA;
  13.         this.xB = xB;
  14.         this.xC = xC;
  15.         this.yA = yA;
  16.         this.yB = yB;
  17.         this.yC = yC;
  18.     }
  19.    
  20.     public Trojkat() {
  21.         this(0,0, 1,0, 1,1);
  22.     }
  23.  
  24.     private double obliczBok(double x1, double y1, double x2, double y2) {
  25.         double bok = Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
  26.         return bok;
  27.     }
  28.    
  29.     public double podajPole() { //POLE LICZONE WZOREM HERONA
  30.         double p = 0.5 * (a+b+c);
  31.         double pole = Math.sqrt(p*(p-a)*(p-b)*(p-c));
  32.         return pole;
  33.     }
  34.    
  35.     public void rysuj() {
  36.         System.out.println("TROJKAT:");
  37.         System.out.println("Wspolrzedne A: (" + xA + "," + yA + "); ");
  38.         System.out.println("Wspolrzedne B: (" + xB + "," + yB + "); ");
  39.         System.out.println("Wspolrzedne C: (" + xC + "," + yC + "); ");
  40.         System.out.println("Dlugosc bokow A,B,C: " + a + "," + b + "," + c);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement