Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.00 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.URL;
  3. import java.net.URLConnection;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.     public static void main(String[] args) {
  8.  
  9.         BaseStation station = new BaseStation(); //Объявили и проинициализировали (создали) объект
  10.  
  11.  
  12.         Scanner input = new Scanner(System.in); //Объявление сканера
  13.         System.out.println("Введите количество базовых станций");
  14.         int Size = input.nextInt(); //Читаем с клавиатуры размер массива и записываем в Size
  15.         /*
  16.         double[] Rxl = new double[Size]; //Создаётся массив с типом данных double и размером Size
  17.         */
  18.         double WnSum = 0;
  19.         double WnLatSum = 0;
  20.         double WnLongSum = 0;
  21.         double[] BaseLatitude = {59.841064,59.841807,59.847227,59.845332,59.844771};
  22.         double[] BaseLongitude = {30.349531,30.352262,30.33951,30.33951,30.357379};
  23.         double SearchPointLatitude = 0;
  24.         double SearchPointLongitude = 0;
  25.         double[] Wn = new double[Size];
  26.  
  27.         for(int i = 0; i < Size; i++){
  28.             System.out.println("Введите "+i+" значение MCC");
  29.             station.MCC = input.next();
  30.  
  31.             System.out.println("Введите "+i+" значение MNC");
  32.             station.MNC = input.next();
  33.  
  34.             System.out.println("Введите "+i+" значение LAC");
  35.             station.LAC = input.next();
  36.  
  37.             System.out.println("Введите "+i+" значение CID");
  38.             station.CID = input.next();
  39.  
  40.             System.out.println("Введите "+i+" значение Rxl");
  41.             station.Rxl = input.nextInt();
  42.  
  43.             //getYandexCoord();
  44.         } // Заполняем массивы первоначальными данными, введёнными с клавиатуры
  45.  
  46.         for(int k = 0; k < Size; k++){
  47.  
  48.             double a = Rxl[k];
  49.             a = a/20;
  50.             Rxl[k] = a;
  51.             double b = Math.pow((double) 10, a);
  52.             Wn[k] = b;
  53.             WnSum += Wn[k];
  54.         } //Вычисляет W(n) и их сумму
  55.  
  56.         for(int i = 0; i < Wn.length & i < BaseLatitude.length; i++){
  57.  
  58.             double a = BaseLatitude[i];
  59.             double b = BaseLongitude[i];
  60.             double c = Wn[i];
  61.             double[] WnLat = new double[Wn.length];
  62.             double[] WnLong = new double[Wn.length];
  63.             double d = a*c;
  64.             double e = b*c;
  65.  
  66.             WnLat[i] = d;
  67.             WnLong[i] = e;
  68.  
  69.                 for(int x = 0; x < WnLat.length; x++){
  70.                     WnLatSum += WnLat[x];
  71.                     WnLongSum += WnLong[x];
  72.                 } //Вычисляет сумму массивов WnLat и WnLong
  73.  
  74.             SearchPointLatitude = WnLatSum/WnSum;
  75.             SearchPointLongitude = WnLongSum/WnSum;
  76.         } //Вычисляет "широту" и "долготу" искомой точки
  77.  
  78.         try (FileWriter writer = new FileWriter("Object`s Coords.txt", false)){
  79.  
  80.             writer.write("Latitude: "+SearchPointLatitude+" & "+"Longitude: "+SearchPointLongitude);
  81.             writer.append('\n');
  82.             writer.flush();
  83.         } //Записывает расчитанные координаты объекта в файл
  84.         catch (IOException ex){
  85.             System.out.println(ex.getMessage());
  86.         }
  87.         theEnd();
  88.     }
  89.     private static void theEnd(){
  90.         System.out.print("The End. Результат записан в файл.");
  91.     } //Метод просто показывающий, что прога отработала, всё посчитала и записала результат в файл
  92.     public static String getYandexCoord(String MCC, String MNC, String LAC, String CID) {
  93.         String res="";
  94.         try {
  95.             URLConnection connection = new URL("http://mobile.maps.yandex.net/cellid_location/?&cellid="+Integer.parseInt(CID,16)
  96.                     +"&operatorid="+Integer.parseInt(MNC)+"&countrycode="+Integer.parseInt(MCC)+"&lac="+Integer.parseInt(LAC,16)).openConnection();
  97.             BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  98.             String line;
  99.             StringBuilder sb = new StringBuilder();
  100.             while((line = br.readLine())!=null) {
  101.                 sb.append(line);
  102.             }
  103.             int begin = sb.toString().indexOf("latitude")+10;
  104.             int end = sb.toString().indexOf(" ", begin)-1;
  105.             res=sb.toString().substring(begin,end)+" ";
  106.             begin = sb.toString().indexOf("longitude")+11;
  107.             end = sb.toString().indexOf(" ", begin)-1;
  108.             res+=sb.toString().substring(begin,end);
  109.         } catch (IOException e) {
  110.             System.out.println(e);
  111.         }
  112.         return res;
  113.     } //Получает координату БС по Яндексу
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement