Venciity

[SoftUni Java] Syntax - 09.PointInsideTheHouse

May 19th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. /* Write a program to check whether a point is inside or outside
  2.  * the house below. The point is given as a pair of floating-point
  3.  * numbers, separated by a space. Your program should print "Inside" or "Outside". */
  4.  
  5. import java.awt.Rectangle;
  6. import java.awt.geom.Path2D;
  7. import java.util.Locale;
  8. import java.util.Scanner;
  9.  
  10. public class PointInsideTheHouse {
  11.     public static void main(String[] args) {
  12.     Locale.setDefault(Locale.ROOT); // invariant culture
  13.    
  14.     double[] xPoints = { 12.5, 12.5, 17.5, 17.5, 20, 20, 22.5, 22.5, 17.5 };
  15.     double[] yPoints = { 8.5, 13.5, 13.5, 8.5, 8.5, 13.5, 13.5, 8.5, 3.5 };
  16.  
  17.     Path2D house = new Path2D.Double();
  18.     house.moveTo(xPoints[0], yPoints[0]);
  19.     for (int i = 1; i < xPoints.length; ++i) {
  20.         house.lineTo(xPoints[i], yPoints[i]);
  21.     }
  22.     house.closePath();
  23.     Rectangle houseBounds = new Rectangle();
  24.     houseBounds = house.getBounds();
  25.     @SuppressWarnings("resource")
  26.     Scanner scanner = new Scanner(System.in);
  27.     double x = scanner.nextDouble();
  28.     double y = scanner.nextDouble();
  29.     if (houseBounds.contains(x, y) && house.contains(x, y)) {
  30.         System.out.println("Inside");
  31.     } else {
  32.         System.out.println("Outside");
  33.     }
  34.     }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment