Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package figury;
- public class Trojkat {
- private double xA,yA,xB,yB,xC,yC;
- private double a = obliczBok(xA,yA,xB,yB);
- private double b = obliczBok(xB,yB,xC,yC);
- private double c = obliczBok(xA,yA,xC,yC);
- public Trojkat(double xA,double yA, double xB,double yB,double xC, double yC) {
- this.xA = xA;
- this.xB = xB;
- this.xC = xC;
- this.yA = yA;
- this.yB = yB;
- this.yC = yC;
- }
- public Trojkat() {
- this(0,0, 1,0, 1,1);
- }
- private double obliczBok(double x1, double y1, double x2, double y2) {
- double bok = Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
- return bok;
- }
- public double podajPole() { //POLE LICZONE WZOREM HERONA
- double p = 0.5 * (a+b+c);
- double pole = Math.sqrt(p*(p-a)*(p-b)*(p-c));
- return pole;
- }
- public void rysuj() {
- System.out.println("TROJKAT:");
- System.out.println("Wspolrzedne A: (" + xA + "," + yA + "); ");
- System.out.println("Wspolrzedne B: (" + xB + "," + yB + "); ");
- System.out.println("Wspolrzedne C: (" + xC + "," + yC + "); ");
- System.out.println("Dlugosc bokow A,B,C: " + a + "," + b + "," + c);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement