Advertisement
dimipan80

C#Exams 1. Inside the Building (on Java Code)

Aug 24th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _1_InsideTheBuilding {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         Scanner scan = new Scanner(System.in);
  8.         int size = scan.nextInt();
  9.  
  10.         for (int i = 0; i < 5; i++) {
  11.             int pointX = scan.nextInt();
  12.             int pointY = scan.nextInt();
  13.  
  14.             boolean pointInsideInBase = checkThePointIsInsideInBase(size,
  15.                     pointX, pointY);
  16.             boolean pointInsideInTower = checkThePointIsInsideInTower(size,
  17.                     pointX, pointY);
  18.  
  19.             String result = (pointInsideInBase || pointInsideInTower) ? "inside"
  20.                     : "outside";
  21.             System.out.println(result);
  22.         }
  23.     }
  24.  
  25.     private static boolean checkThePointIsInsideInBase(int size, int x, int y) {
  26.         // TODO Auto-generated method stub
  27.         int maxX = 3 * size;
  28.         boolean isInside = x >= 0 && x <= maxX && y >= 0 && y <= size;
  29.         return isInside;
  30.     }
  31.  
  32.     private static boolean checkThePointIsInsideInTower(int size, int x, int y) {
  33.         // TODO Auto-generated method stub
  34.         int maxX = 2 * size;
  35.         int maxY = 4 * size;
  36.         boolean isInside = x >= size && x <= maxX && y >= size && y <= maxY;
  37.         return isInside;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement