LardaX

ToTheStarsTestsWithArrays

Jan 17th, 2017
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class ToTheStarsTestsWithArrays {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         ArrayList<double[]> systemsCoordinates = new ArrayList<>();
  8.         String[] systems = new String[3];
  9.  
  10.         for (int i = 0; i < 3; i++) {
  11.             String[] input = scanner.nextLine().split(" ");
  12.             systems[i] = input[0];
  13.             systemsCoordinates.add(i, new double[] { Double.parseDouble(input[1]), Double.parseDouble(input[2])});
  14.         }
  15.  
  16.         String[] location = scanner.nextLine().split(" ");
  17.         int moves = Integer.parseInt(scanner.nextLine());
  18.  
  19.         double currentLocationX = Double.parseDouble(location[0]);
  20.         double currentLocationY = Double.parseDouble(location[1]);
  21.  
  22.         while (moves >= 0) {
  23.  
  24.             String currentLocation = "space";
  25.  
  26.             for (int i = 0; i < systemsCoordinates.size(); i++) {
  27.  
  28.                 double leftEdge = systemsCoordinates.get(i)[0] - 1;
  29.                 double rightEdge = systemsCoordinates.get(i)[0] + 1;
  30.                 double lowerEdge = systemsCoordinates.get(i)[1] - 1;
  31.                 double upperEdge = systemsCoordinates.get(i)[1] + 1;
  32.  
  33.                 if (currentLocationX >= leftEdge && currentLocationX <= rightEdge
  34.                         && currentLocationY >= lowerEdge && currentLocationY <= upperEdge) {
  35.                     currentLocation = systems[i];
  36.                 }
  37.             }
  38.             System.out.println(currentLocation.toLowerCase());
  39.             currentLocationY++;
  40.             moves--;
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment