Advertisement
Farahim

main5.java

Sep 2nd, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. /**
  2. * Farahim Ibrahimli
  3. * Homework 1 Question 5
  4. *
  5. */
  6.  
  7. import java.util.Scanner;
  8.  
  9. public class Question5 {
  10.  
  11. private static Scanner in = new Scanner(System.in);
  12.  
  13.  
  14. public static double readDouble(String prompt) {
  15. System.out.print(prompt);
  16. return in.nextDouble();
  17. }
  18.  
  19. public static double calculateDistance(double startX, double startY, double endX, double endY) {
  20. return Math.sqrt(Math.pow(startX - endX, 2) + Math.pow(startY - endY, 2));
  21. }
  22.  
  23. public static void main(String[] args) {
  24.  
  25. double aX = readDouble("Enter Point A X-Coordinate: ");
  26. double aY = readDouble("Enter Point A Y-Coordinate: ");
  27.  
  28. double bX = readDouble("Enter Point B X-Coordinate: ");
  29. double bY = readDouble("Enter Point B Y-Coordinate: ");
  30.  
  31. double cX = readDouble("Enter Point C X-Coordinate: ");
  32. double cY = readDouble("Enter Point C Y-Coordinate: ");
  33.  
  34. double aToB = calculateDistance(aX, aY, bX, bY);
  35. double bToC = calculateDistance(bX, bY, cX, cY);
  36. double cToA = calculateDistance(cX, cY, aX, aY);
  37.  
  38.  
  39. if((aToB + bToC > cToA) || (bToC + cToA > aToB) || (cToA + aToB > bToC)) {
  40. System.out.println("It is a real triangle");
  41. } else {
  42. System.out.println("It is a fake triangle");
  43. }
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement