Advertisement
viraldim

Points in House

May 13th, 2014
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. /*9.Write a program to check whether a point is inside or outside the house 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.Scanner;
  6.  
  7. public class PointsInsideTheHouse {
  8.    
  9.     static double xHRBotL = 12.5;
  10.     static double yHRBotLR = 8.5;
  11.     static double xHRTop = 17.5;
  12.     static double yHRTop = 3.5;
  13.     static double xHRBotR = 22.5;
  14.     static double xDiff = xHRTop - xHRBotL;
  15.     static double yDiff = yHRTop - yHRBotLR;
  16.     static double angleRoof = Math.abs(Math.toDegrees(Math.atan2(yDiff, xDiff)));
  17.        
  18.     public static boolean CheckAngle (double x, double y){
  19.         boolean isBigger = true;
  20.        
  21.         if (x < 17.5) {
  22.             double xDiffL = x-xHRBotL;
  23.             double yDiffL = y-yHRBotLR;
  24.             double angle =Math.abs(Math.toDegrees(Math.atan2(yDiffL, xDiffL)));
  25.             if (angle > angleRoof) {
  26.                 isBigger= false;
  27.             }
  28.         }
  29.         else {
  30.             double xDiffR = xHRBotR -x;
  31.             double yDiffR = yHRBotLR -y ;
  32.             double angle =Math.abs(Math.toDegrees(Math.atan2(yDiffR, xDiffR)));
  33.             if (angle != 0 && angle > angleRoof) {
  34.                 isBigger = false;
  35.             }
  36.         }
  37.         return isBigger;
  38.     }
  39.    
  40.     public static void main(String[] args) {
  41.         Scanner input = new Scanner(System.in);
  42.         double x,y;
  43.        
  44.         System.out.println("Enter coords of the point");
  45.        
  46.         x = input.nextDouble();
  47.         y = input.nextDouble();
  48.        
  49.        
  50.         if (x >= 12.5 && x <=17.5 && y>=8.5 && y<=13.5) {
  51.             System.out.println("Inside");
  52.         }
  53.         else if (x >= 20 && x <=22.5 && y>=8.5 && y<=13.5) {
  54.             System.out.println("Inside");
  55.         }
  56.         else if(CheckAngle(x, y) && y >=3.5 && y <= 8.5){
  57.             System.out.println("Inside");
  58.         }
  59.         else {
  60.             System.out.println("Outside");
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement