Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TrianguloEquilatero {
- private double x, y, base, altura;
- TrianguloEquilatero (double xVS, double yVS, double xVD, double yVD) {
- this.setY(yVD);
- this.setX(xVS, xVD);
- this.setBase(xVD);
- this.setAltura(yVD, yVS);
- }
- public double area () {
- return (this.base * this.altura) / 2;
- }
- public double perimetro () {
- return (3 * this.base);
- }
- public double getX () {
- return this.x;
- }
- private void setX (double xVS, double xVD) {
- /*
- xVS = (xVD + x) / 2
- xVD + x = xVS * 2
- x = (xVS * 2) - xVD
- */
- this.x = (xVS * 2) - xVD;
- }
- public double getBase () {
- return this.base;
- }
- private void setBase (double xVD) {
- this.base = xVD - this.x;
- }
- public double getAltura () {
- return this.altura;
- }
- private void setAltura (double yVD, double yVS) {
- this.altura = yVD - yVS;
- }
- public double getY () {
- return this.y;
- }
- private void setY (double yVD) {
- this.y = yVD;
- }
- public void mover(double dx, double dy) {
- this.x += dx;
- this.y += dy;
- }
- void redimensionar (double fatorEscala) {
- this.base *= fatorEscala;
- this.altura *= fatorEscala;
- this.perimetro();
- this.area();
- }
- public String toString () {
- double perimetro = this.perimetro();
- double area = this.area();
- return "(" + this.x + ", " + this.y + ") :.: <" + this.base + ", " + this.altura + "> :.: {" + area + " - " + perimetro + "}";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement