Advertisement
Guest User

Prostokąt

a guest
May 25th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. public class Prostokat {
  2.     Punkt lg;
  3.     Punkt pd;
  4.  
  5.     Prostokat() {
  6.         this.lg = new Punkt(0, 1);
  7.         this.pd = new Punkt(1, 0);
  8.     }
  9.  
  10.     Prostokat(Punkt p1, Punkt p2) {
  11.         this.lg = p1;
  12.         this.pd = p2;
  13.     }
  14.  
  15.     Prostokat(int x1, int y1, int x2, int y2) {
  16.         this.lg = new Punkt(x1, y1);
  17.         this.pd = new Punkt(x2, y2);
  18.     }
  19.  
  20.     Prostokat(Prostokat pr) {
  21.         this.lg = new Punkt(pr.lg);
  22.         this.pd = new Punkt(pr.pd);
  23.     }
  24.  
  25.     public Punkt getLg() {
  26.         return this.lg;
  27.     }
  28.  
  29.     public void setLg(Punkt lg) {
  30.         this.lg = lg;
  31.     }
  32.  
  33.     public Punkt getPd() {
  34.         return this.pd;
  35.     }
  36.  
  37.     public void setPd(Punkt pd) {
  38.         this.pd = pd;
  39.     }
  40.  
  41.     int pole() {
  42.         int a = Math.abs(this.lg.pobierzX() - this.pd.pobierzX());
  43.         int b = Math.abs(this.lg.pobierzY() - this.pd.pobierzY());
  44.         return a * b;
  45.     }
  46.  
  47.     int obwod() {
  48.         int a = Math.abs(this.lg.pobierzX() - this.pd.pobierzX());
  49.         int b = Math.abs(this.lg.pobierzY() - this.pd.pobierzY());
  50.         return 2 * a + 2 * b;
  51.     }
  52.  
  53.     public String toString() {
  54.         return "(" + this.lg.pobierzX() + ", " + this.lg.pobierzY() + "), " + "(" + this.pd.pobierzX() + ", " + this.pd.pobierzY() + ")";
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement