Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a program to check whether a point is inside or outside of the figure 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.Locale;
- import java.util.Scanner;
- public class _03_PointsInsideFigure {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Locale.setDefault(Locale.ROOT);
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter 2 real numbers for coordinates (x, y) of your point: ");
- double pointX = scan.nextDouble();
- double pointY = scan.nextDouble();
- boolean pointInsideWholeRectangle = checkThePointIsInsideInWholeRectangle(pointX, pointY);
- boolean pointOutsideEmptyColumn = checkThePointIsOutsideOfEmptyColumn(pointX, pointY);
- if (pointInsideWholeRectangle && pointOutsideEmptyColumn) {
- System.out.println("That Point is Inside !");
- } else {
- System.out.println("That Point is Outside !");
- }
- }
- private static boolean checkThePointIsOutsideOfEmptyColumn(double pointX, double pointY) {
- // TODO Auto-generated method stub
- double minX = 17.5, maxX = minX + 2.5;
- double minY = 8.5, maxY = minY + 5;
- return pointX <= minX || pointX >= maxX || pointY <= minY || pointY >= maxY;
- }
- private static boolean checkThePointIsInsideInWholeRectangle(double pointX, double pointY) {
- // TODO Auto-generated method stub
- double minX = 12.5, maxX = minX + 10;
- double minY = 6, maxY = minY + 7.5;
- return pointX >= minX && pointX <= maxX && pointY >= minY && pointY <= maxY;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement