Advertisement
dimipan80

Points Inside a Figure

Aug 17th, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. /* Write a program to check whether a point is inside or outside of the figure below.
  2.  * The point is given as a pair of floating-point numbers, separated by a space.
  3.  * Your program should print "Inside" or "Outside". */
  4.  
  5. import java.util.Locale;
  6. import java.util.Scanner;
  7.  
  8. public class _03_PointsInsideFigure {
  9.  
  10.     public static void main(String[] args) {
  11.         // TODO Auto-generated method stub
  12.         Locale.setDefault(Locale.ROOT);
  13.         Scanner scan = new Scanner(System.in);
  14.         System.out.print("Enter 2 real numbers for coordinates (x, y) of your point: ");
  15.         double pointX = scan.nextDouble();
  16.         double pointY = scan.nextDouble();
  17.  
  18.         boolean pointInsideWholeRectangle = checkThePointIsInsideInWholeRectangle(pointX, pointY);
  19.  
  20.         boolean pointOutsideEmptyColumn = checkThePointIsOutsideOfEmptyColumn(pointX, pointY);
  21.  
  22.         if (pointInsideWholeRectangle && pointOutsideEmptyColumn) {
  23.             System.out.println("That Point is Inside !");
  24.         } else {
  25.             System.out.println("That Point is Outside !");
  26.         }
  27.     }
  28.  
  29.     private static boolean checkThePointIsOutsideOfEmptyColumn(double pointX, double pointY) {
  30.         // TODO Auto-generated method stub
  31.         double minX = 17.5, maxX = minX + 2.5;
  32.         double minY = 8.5, maxY = minY + 5;
  33.         return pointX <= minX || pointX >= maxX || pointY <= minY || pointY >= maxY;
  34.     }
  35.  
  36.     private static boolean checkThePointIsInsideInWholeRectangle(double pointX, double pointY) {
  37.         // TODO Auto-generated method stub
  38.         double minX = 12.5, maxX = minX + 10;
  39.         double minY = 6, maxY = minY + 7.5;
  40.         return pointX >= minX && pointX <= maxX && pointY >= minY && pointY <= maxY;
  41.     }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement