fork download
  1.  
  2. import static java.lang.Math.sqrt;
  3.  
  4.  
  5. public class ThreePoints {
  6.  
  7. float x0;
  8. float y0;
  9. float x1;
  10. float y1;
  11. float x2;
  12. float y2;
  13.  
  14.  
  15. public ThreePoints(){
  16. this.x0 = 0;
  17. this.y0 = 0;
  18. this.x1 = 0;
  19. this.y1 = 0;
  20. this.x2 = 0;
  21. this.y2 = 0;
  22.  
  23. }
  24. public ThreePoints(float x0, float y0, float x1, float y1, float x2, float y2){
  25. this.x0 = x0;
  26. this.y0 = y0;
  27. this.x1 = x1;
  28. this.y1 = y1;
  29. this.x2 = x2;
  30. this.y2 = y2;
  31. }
  32. public double getLength(int side){
  33.  
  34.  
  35. if(side == 0 && isTriangle()){
  36. return Math.sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));
  37. } else if (side == 1 && isTriangle()){
  38. return Math.sqrt((x2-x0) * (x2-x0) + (y2-y0) * (y1-y0));
  39. } else if (side == 2 && isTriangle()){
  40. return Math.sqrt((x1-x0) * (x1-x0) + (y1-y0) * (y1-y0));
  41. }else{ return 0;
  42.  
  43. }
  44. }
  45. public double getAngle(int vertex){
  46.  
  47. if(vertex == 0 && isTriangle()) {
  48. double angle = Math.acos((-Math.pow(this.getLength(0),2)
  49. +Math.pow(this.getLength(1),2)
  50. +Math.pow(this.getLength(2),2))
  51. /(2*this.getLength(1)*this.getLength(2)));
  52. return angle;
  53. } else if(vertex == 1 && isTriangle()) {
  54. double angle = Math.acos((Math.pow(this.getLength(0),2)- Math.pow(this.getLength(1),2)
  55. +Math.pow(this.getLength(2),2))/
  56. (2*this.getLength(0)*this.getLength(2)));
  57. return angle;
  58. } else if(vertex == 2 && isTriangle()){
  59. double angle = Math.acos((Math.pow(this.getLength(0),2)
  60. +Math.pow(this.getLength(1),2)- Math.pow(this.getLength(2),2)) /(2*this.getLength(0)*this.getLength(1)));
  61. return angle;
  62. } else {
  63. return 0;
  64. }
  65.  
  66.  
  67. }
  68. public boolean isTriangle(){
  69.  
  70. if (!(x0 * (y1-y2) + x1 * (y2-y0) + x2 * (y0-y1) == 0)){
  71. return true;
  72. }
  73. return false;
  74. }
  75. public boolean isEquilateral(){
  76. if (getLength(0) != getLength(1))
  77. return false;
  78. if (getLength(0) != getLength(2))
  79. return false;
  80. if (getLength(1) != getLength(2))
  81. return false;
  82. return true;
  83. }
  84. public boolean isIsosceles(){
  85. if (getLength(0) == getLength(1))
  86. return true;
  87. if (getLength(0) == getLength(2))
  88. return true;
  89. if (getLength(1) == getLength(2))
  90. return true;
  91. return false;
  92.  
  93. }
  94. public boolean isScalene(){
  95. if (getLength(0) == getLength(1))
  96. return true;
  97. if (getLength(0) == getLength(2))
  98. return true;
  99. if (getLength(1) == getLength(2))
  100. return true;
  101. return false;
  102. }
  103. public boolean isAcute(){
  104. if (getAngle(0) < 90 && getAngle(1) < 90 && getAngle(2) < 90){
  105. return true;
  106. }
  107. return false;
  108. }
  109. public boolean isObtuse(){
  110. if (getAngle(0) > 90 && getAngle(1) > 90 && getAngle(2) > 90){
  111. return true;
  112. }
  113. return false;
  114. }
  115. public double getPerimeter(){
  116. double perimeter;
  117. perimeter = (getLength(0) + getLength(1) + getLength(2));
  118. return perimeter;
  119. }
  120. public boolean isRight(){
  121. if (getAngle(0) == 90 && getAngle(1) == 90 && getAngle(2) == 90){
  122. return true;
  123. }
  124. return false;
  125. }
  126. public double getArea(){
  127. double s = ((getLength(0) + getLength(1) + getLength(2))/2);
  128. double area = sqrt(s * (s-getLength(0))*(s-getLength(1))*(s-getLength(2)));
  129.  
  130. return area;
  131. }
  132. private boolean approxEqual (double x, double y) {
  133. return Math.abs(x - y) <= 1E-12;
  134. }
  135. }
  136.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: class ThreePoints is public, should be declared in a file named ThreePoints.java
public class ThreePoints {
       ^
1 error
stdout
Standard output is empty