Last active
August 29, 2015 14:01
-
-
Save garbuchev/5e3a7b98dc0b94213d2f to your computer and use it in GitHub Desktop.
Problem 9.** Points inside the House
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class P09PointsInsideHouse { | |
public static void main(String[] args) { | |
Scanner scan = new Scanner(System.in); | |
double x = scan.nextDouble(); | |
double y = scan.nextDouble(); | |
//To simplify the problem let's divide the roof into 2 triangles | |
//at the line (17.5, 3)(17.5, 8.5) | |
boolean checkTriangle1 = insideTriangle1(x, y); | |
boolean checkTriangle2 = insideTriangle2(x, y); | |
boolean checkRectangle1 = insideRectangle1(x, y); | |
boolean checkRectangle2 = insideRectangle2(x, y); | |
boolean result = checkRectangle1 || checkRectangle2 || checkTriangle1 | |
|| checkTriangle2; | |
if (result) { | |
System.out.println("Inside"); | |
} else { | |
System.out.println("Outside"); | |
} | |
} | |
private static boolean insideRectangle2(double x, double y) { | |
// TODO Auto-generated method stub | |
if (x >= 20 && x <= 22.5 && y >= 8.5 && y <= 13.5) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
private static boolean insideRectangle1(double x, double y) { | |
// TODO Auto-generated method stub | |
if (x >= 12.5 && x <= 17.5 && y >= 8.5 && y <= 13.5) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
private static boolean insideTriangle2(double x, double y) { | |
// TODO Auto-generated method stub | |
if (x >= 17.5 && x <= 22.5 && y >= 3.5 && y <= 8.5 && (x - y) <= 14) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
private static boolean insideTriangle1(double x, double y) { | |
// TODO Auto-generated method stub | |
if (x >= 12.5 && x <= 17.5 && y >= 3.5 && y <= 8.5 && (x + y) >= 21) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment