Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. public class TrianguloEquilatero {
  2. private double x, y, base, altura;
  3.  
  4. TrianguloEquilatero (double xVS, double yVS, double xVD, double yVD) {
  5. this.setY(yVD);
  6. this.setX(xVS, xVD);
  7. this.setBase(xVD);
  8. this.setAltura(yVD, yVS);
  9. }
  10.  
  11. public double area () {
  12. return (this.base * this.altura) / 2;
  13. }
  14.  
  15. public double perimetro () {
  16. return (3 * this.base);
  17. }
  18.  
  19. public double getX () {
  20. return this.x;
  21. }
  22.  
  23. private void setX (double xVS, double xVD) {
  24. /*
  25. xVS = (xVD + x) / 2
  26. xVD + x = xVS * 2
  27. x = (xVS * 2) - xVD
  28. */
  29. this.x = (xVS * 2) - xVD;
  30. }
  31.  
  32. public double getBase () {
  33. return this.base;
  34. }
  35.  
  36. private void setBase (double xVD) {
  37. this.base = xVD - this.x;
  38. }
  39.  
  40. public double getAltura () {
  41. return this.altura;
  42. }
  43.  
  44. private void setAltura (double yVD, double yVS) {
  45. this.altura = yVD - yVS;
  46. }
  47.  
  48. public double getY () {
  49. return this.y;
  50. }
  51.  
  52. private void setY (double yVD) {
  53. this.y = yVD;
  54. }
  55.  
  56. public void mover(double dx, double dy) {
  57. this.x += dx;
  58. this.y += dy;
  59. }
  60.  
  61. void redimensionar (double fatorEscala) {
  62. this.base *= fatorEscala;
  63. this.altura *= fatorEscala;
  64. this.perimetro();
  65. this.area();
  66. }
  67.  
  68. public String toString () {
  69. double perimetro = this.perimetro();
  70. double area = this.area();
  71. return "(" + this.x + ", " + this.y + ") :.: <" + this.base + ", " + this.altura + "> :.: {" + area + " - " + perimetro + "}";
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement