LardaX

ToTheStarsTests

Jan 17th, 2017
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.42 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class ToTheStarsTests {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         ArrayList<StarSystem> systems = new ArrayList<>();
  9.  
  10.         for (int i = 0; i < 3; i++) {
  11.             String[] input = scanner.nextLine().split(" ");
  12.             String systemName = input[0];
  13.             double centerPointX = Double.parseDouble(input[1]);
  14.             double centerPointY = Double.parseDouble(input[2]);
  15.  
  16.             StarSystem currentSystem = new StarSystem(systemName, centerPointX, centerPointY);
  17.  
  18.             systems.add(currentSystem);
  19.         }
  20.  
  21.         String[] location = scanner.nextLine().split(" ");
  22.         int moves = Integer.parseInt(scanner.nextLine());
  23.  
  24.         double currentLocationX = Double.parseDouble(location[0]);
  25.         double currentLocationY = Double.parseDouble(location[1]);
  26.  
  27.         while (moves >= 0) {
  28.             String currentLocation = "space";
  29.  
  30.             for (StarSystem system : systems) {
  31.                 if (system.isInsideStarSystem(currentLocationX, currentLocationY)){
  32.                     currentLocation = system.getName().toLowerCase();
  33.                 }
  34.             }
  35.  
  36.             System.out.println(currentLocation);
  37.             currentLocationY++;
  38.             moves--;
  39.         }
  40.     }
  41. }
  42.  
  43. class StarSystem {
  44.     String name;
  45.     private double centerPointX;
  46.     private double centerPointY;
  47.  
  48.     private double leftEdge;
  49.     private double rightEdge;
  50.  
  51.     private double lowerEdge;
  52.     private double upperEdge;
  53.  
  54.     public StarSystem(String name, double centerPointX, double centerPointY) {
  55.         this.name = name;
  56.         this.centerPointX = centerPointX;
  57.         this.centerPointY = centerPointY;
  58.         this.leftEdge = this.getCenterPointX() - 1;
  59.         this.rightEdge = this.getCenterPointX() + 1;
  60.         this.lowerEdge = centerPointY - 1;
  61.         this.upperEdge = centerPointY + 1;
  62.     }
  63.  
  64.     public boolean isInsideStarSystem(double coordinateX, double coordinateY) {
  65.         if (coordinateX >= this.leftEdge && coordinateX <= this.rightEdge
  66.                 && coordinateY >= this.lowerEdge && coordinateY <= this.upperEdge) {
  67.             return true;
  68.         }
  69.  
  70.         return false;
  71.     }
  72.  
  73.     public String getName() {
  74.         return name;
  75.     }
  76.  
  77.     public void setName(String name) {
  78.         this.name = name;
  79.     }
  80.  
  81.     public double getCenterPointX() {
  82.         return centerPointX;
  83.     }
  84.  
  85.     public void setCenterPointX(double centerPointX) {
  86.         this.centerPointX = centerPointX;
  87.     }
  88.  
  89.     public double getCenterPointY() {
  90.         return centerPointY;
  91.     }
  92.  
  93.     public void setCenterPointY(double centerPointY) {
  94.         this.centerPointY = centerPointY;
  95.     }
  96.  
  97.     public double getLeftEdge() {
  98.         return leftEdge;
  99.     }
  100.  
  101.     public void setLeftEdge(double leftEdge) {
  102.         this.leftEdge = leftEdge;
  103.     }
  104.  
  105.     public double getRightEdge() {
  106.         return rightEdge;
  107.     }
  108.  
  109.     public void setRightEdge(double rightEdge) {
  110.         this.rightEdge = rightEdge;
  111.     }
  112.  
  113.     public double getLowerEdge() {
  114.         return lowerEdge;
  115.     }
  116.  
  117.     public void setLowerEdge(double lowerEdge) {
  118.         this.lowerEdge = lowerEdge;
  119.     }
  120.  
  121.     public double getUpperEdge() {
  122.         return upperEdge;
  123.     }
  124.  
  125.     public void setUpperEdge(double upperEdge) {
  126.         this.upperEdge = upperEdge;
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment