Advertisement
Guest User

exam1 judge java

a guest
Sep 6th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.43 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     private static Rectangle vertical = new Rectangle();
  8.     private static Rectangle horizontal = new Rectangle();
  9.  
  10.     public static void main(String[] args) {
  11.         @SuppressWarnings("resource")
  12.         Scanner scanner = new Scanner(System.in);
  13.  
  14.         double x = scanner.nextDouble();
  15.         double y = scanner.nextDouble();
  16.         double r = scanner.nextDouble();
  17.  
  18.         double rectVerticalX = x - r/2;
  19.         double rectVerticalY = y + r;
  20.         double rectVerticalWidth = r;
  21.         double rectVerticalHeight = 2 * r;
  22.  
  23.         vertical.setX(rectVerticalX);
  24.         vertical.setY(rectVerticalY);
  25.         vertical.setWidth(rectVerticalWidth);
  26.         vertical.setHeight(rectVerticalHeight);
  27.  
  28.         double rectHorizontalX = x - r;
  29.         double rectHorizontalY = y + r/2;
  30.         double rectHorizontalWidth = 2 * r;
  31.         double rectHorizontalHeight = r;
  32.         horizontal.setX(rectHorizontalX);
  33.         horizontal.setY(rectHorizontalY);
  34.         horizontal.setWidth(rectHorizontalWidth);
  35.         horizontal.setHeight(rectHorizontalHeight);
  36.  
  37.  
  38.         int n = scanner.nextInt();
  39.         for (int i = 0; i < n; i++) {
  40.             double pX = scanner.nextDouble();
  41.             double pY = scanner.nextDouble();
  42.  
  43.             boolean isWithinTarget = vertical.contains(pX, pY) || horizontal.contains(pX, pY);
  44.             if (isWithinTarget) {
  45.                 System.out.println("yes");
  46.             } else {
  47.                 System.out.println("no");
  48.             }
  49.         }
  50.  
  51.     }
  52.  
  53. }
  54.  
  55. class Rectangle {
  56.  
  57.     private double x;
  58.     private double y;
  59.     private double width;
  60.     private double height;
  61.    
  62.     public double getX() {
  63.         return x;
  64.     }
  65.  
  66.     public void setX(double x) {
  67.         this.x = x;
  68.     }
  69.  
  70.     public double getY() {
  71.         return y;
  72.     }
  73.  
  74.     public void setY(double y) {
  75.         this.y = y;
  76.     }
  77.  
  78.     public double getWidth() {
  79.         return width;
  80.     }
  81.  
  82.     public void setWidth(double width) {
  83.         this.width = width;
  84.     }
  85.  
  86.     public double getHeight() {
  87.         return height;
  88.     }
  89.  
  90.     public void setHeight(double height) {
  91.         this.height = height;
  92.     }
  93.  
  94.     public boolean contains(double x, double y) {
  95.  
  96.         boolean isInside = y <= this.y && y >= this.y - this.height && x >= this.x && x <= this.x + this.width;
  97.         return isInside;
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement