Created
February 5, 2021 18:17
-
-
Save NinoDLC/8407e3a18c0295bf38ed2d5ed55cf1a4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 HelloWorld { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
int nbEntry = scanner.nextInt(); | |
Rectangle smallYellow = new Rectangle(25, 50, 20, 45); | |
Rectangle blue = new Rectangle(10, 85, 10, 55); | |
Rectangle redOne = new Rectangle(15, 45, 60, 70); | |
Rectangle redTwo = new Rectangle(60, 85, 60, 70); | |
Rectangle bigYellow = new Rectangle(0, 90, 0, 70); | |
for (int i = 0; i < nbEntry; i++) { | |
int x = scanner.nextInt(); | |
int y = scanner.nextInt(); | |
if (smallYellow.isInside(x, y)) { | |
System.out.println("Dans une zone jaune"); | |
} else if (blue.isInside(x, y)) { | |
System.out.println("Dans une zone bleue"); | |
} else if (redOne.isInside(x, y) || redTwo.isInside(x, y)) { | |
System.out.println("Dans une zone rouge"); | |
} else if (bigYellow.isInside(x, y)) { | |
System.out.println("Dans une zone jaune"); | |
} else { | |
System.out.println("En dehors de la feuille"); | |
} | |
} | |
} | |
private static class Rectangle { | |
private final int x1; | |
private final int x2; | |
private final int y1; | |
private final int y2; | |
public Rectangle(int x1, int x2, int y1, int y2) { | |
this.x1 = x1; | |
this.x2 = x2; | |
this.y1 = y1; | |
this.y2 = y2; | |
} | |
public boolean isInside(int x, int y) { | |
return x > x1 && x < x2 && y > y1 && y < y2; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment