Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. //This program determines if 2 triangles are congruent given their vertexes.
  2. // Author: Eyal Oren
  3. // Date:
  4.  
  5. import java.util.Scanner;
  6. public class Congruent
  7. {
  8. public static void main(String[] args)
  9. {
  10. Scanner scan = new Scanner(System.in); ////Creating a scanner to take input from user.
  11. System.out.println("This program determines if two triangles are congruent, given "
  12. + " their vertexes.");
  13. System.out.println("Please enter the three vertexes "
  14. + "of each triangle.");
  15.  
  16. // Defining the vertexes type, and asking the user for their value.
  17.  
  18. double x11 = scan.nextDouble();
  19. double y11 = scan.nextDouble();
  20.  
  21. double x12 = scan.nextDouble();
  22. double y12 = scan.nextDouble();
  23.  
  24. double x13 = scan.nextDouble();
  25. double y13 = scan.nextDouble();
  26.  
  27. double x21 = scan.nextDouble();
  28. double y21 = scan.nextDouble();
  29.  
  30. double x22 = scan.nextDouble();
  31. double y22 = scan.nextDouble();
  32.  
  33. double x23 = scan.nextDouble();
  34. double y23 = scan.nextDouble();
  35.  
  36. double a1, b1,c1, a2, b2, c2; //Defining the type of the three lengths of each triangle.
  37.  
  38. //Calculating the lenghts using Distance equation.
  39.  
  40. a1 = Math.sqrt(Math.pow(x11-x12,2) + Math.pow(y11-y12,2));
  41. b1 = Math.sqrt(Math.pow(x11-x13,2) + Math.pow(y11-y13,2));
  42. c1 = Math.sqrt(Math.pow(x12-x13,2) + Math.pow(y12-y13,2));
  43.  
  44. a2 = Math.sqrt(Math.pow(x21-x22,2) + Math.pow(y21-y22,2));
  45. b2 = Math.sqrt(Math.pow(x21-x23,2) + Math.pow(y21-y23,2));
  46. c2 = Math.sqrt(Math.pow(x22-x23,2) + Math.pow(y22-y23,2));
  47.  
  48. //Creating the condition to determine if the two triangles are congruent.
  49.  
  50. if( (a1 == a2 && b1 == b2 && c1 == c2) ||
  51. (a1 == a2 && b1 == c2 && c1 == b2) ||
  52. (a1 == b2 && b1 == a2 && c1 == c2) ||
  53. (a1 == c2 && b1 == b2 && c1 == a2) ||
  54. (a1 == c2 && b1 == a2 && c1 == b2) ||
  55. (a1 == b2 && b1 == c2 && c1 == a2) )
  56.  
  57. System.out.println("The triangles are congruent");
  58. else
  59. System.out.println("The triangles aren't congruent");
  60.  
  61.  
  62.  
  63.  
  64. } //end of method main
  65. } //end of class Congruent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement