package téglalap;

/**
 * @author Daniel "3ICE" Berezvai
 */
public class Téglalap {

  private double ax, ay, bx, by;

  public Téglalap(double ax, double ay, double bx, double by) {
    //Két szemközti csúcs koordinátáival (4 szám)
    this.ax = ax;
    this.bx = bx;
    this.ay = ay;
    this.by = by;
  }

  public Téglalap(double a, double b) {
    //Oldalhosszakkal
    this.ax = 0;
    this.ay = a;
    this.bx = b;
    this.by = 0;
  }

  public Téglalap(Coordinate pos, double a, double b) {
    //Bal felső csúcs koordinátáival és oldalhosszakkal
    this.ax = pos.x;
    this.ay = pos.y;
    this.bx = ax + a;
    this.by = ay + b;
  }

  public Téglalap(Coordinate a, Coordinate b) {
    //Két szemközti csúcs koordinátáival
    this.ax = a.x;
    this.bx = b.x;
    this.ay = a.y;
    this.by = b.y;
  }

  public double getBy() {
    return by;
  }

  public double getBx() {
    return bx;
  }

  public double getAy() {
    return ay;
  }

  public double getAx() {
    return ax;
  }

  public String getCoords() {
    return "(" + getAx() + "; " + getAy() + "), (" + getBx() + "; " + getBy() + ")";
  }

  public double getA() {
    return Math.abs(ax - bx);
  }

  public double getB() {
    return Math.abs(ay - by);
  }

  double getKerület() {
    return 2 * (getA() + getB());
  }

  double getTerület() {
    return getA() * getB();
  }

  void Kiír() {
    /* Cél:
     *   +---------+
     *   |         |
     *   +---------+
     *
     */

    //Első sor:
    String oldal = "+";
    for (int i = 0; i < getA() - 2; i++) {
      oldal += "-";
    }
    oldal += "+";
    System.out.println(oldal);

    //Közepe:
    String szélek = "";
    for (int i = 0; i < getB() - 2; i++) {
      szélek += "|";
      for (int j = 0; j < getA() - 2; j++) {
        szélek += " ";
      }
      szélek += "|\n";
    }
    System.out.print(szélek);

    //Utolsó sor ugyan az, mint az első:
    System.out.println(oldal);
  }
}
