Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*9.Write a program to check whether a point is inside or outside the house below.
- * The point is given as a pair of floating-point numbers, separated by a space.
- * Your program should print "Inside" or "Outside"*/
- import java.util.Scanner;
- public class PointsInsideTheHouse {
- static double xHRBotL = 12.5;
- static double yHRBotLR = 8.5;
- static double xHRTop = 17.5;
- static double yHRTop = 3.5;
- static double xHRBotR = 22.5;
- static double xDiff = xHRTop - xHRBotL;
- static double yDiff = yHRTop - yHRBotLR;
- static double angleRoof = Math.abs(Math.toDegrees(Math.atan2(yDiff, xDiff)));
- public static boolean CheckAngle (double x, double y){
- boolean isBigger = true;
- if (x < 17.5) {
- double xDiffL = x-xHRBotL;
- double yDiffL = y-yHRBotLR;
- double angle =Math.abs(Math.toDegrees(Math.atan2(yDiffL, xDiffL)));
- if (angle > angleRoof) {
- isBigger= false;
- }
- }
- else {
- double xDiffR = xHRBotR -x;
- double yDiffR = yHRBotLR -y ;
- double angle =Math.abs(Math.toDegrees(Math.atan2(yDiffR, xDiffR)));
- if (angle != 0 && angle > angleRoof) {
- isBigger = false;
- }
- }
- return isBigger;
- }
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- double x,y;
- System.out.println("Enter coords of the point");
- x = input.nextDouble();
- y = input.nextDouble();
- if (x >= 12.5 && x <=17.5 && y>=8.5 && y<=13.5) {
- System.out.println("Inside");
- }
- else if (x >= 20 && x <=22.5 && y>=8.5 && y<=13.5) {
- System.out.println("Inside");
- }
- else if(CheckAngle(x, y) && y >=3.5 && y <= 8.5){
- System.out.println("Inside");
- }
- else {
- System.out.println("Outside");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement