Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- BaseStation station = new BaseStation(); //Объявили и проинициализировали (создали) объект
- Scanner input = new Scanner(System.in); //Объявление сканера
- System.out.println("Введите количество базовых станций");
- int Size = input.nextInt(); //Читаем с клавиатуры размер массива и записываем в Size
- /*
- double[] Rxl = new double[Size]; //Создаётся массив с типом данных double и размером Size
- */
- double WnSum = 0;
- double WnLatSum = 0;
- double WnLongSum = 0;
- double[] BaseLatitude = {59.841064,59.841807,59.847227,59.845332,59.844771};
- double[] BaseLongitude = {30.349531,30.352262,30.33951,30.33951,30.357379};
- double SearchPointLatitude = 0;
- double SearchPointLongitude = 0;
- double[] Wn = new double[Size];
- for(int i = 0; i < Size; i++){
- System.out.println("Введите "+i+" значение MCC");
- station.MCC = input.next();
- System.out.println("Введите "+i+" значение MNC");
- station.MNC = input.next();
- System.out.println("Введите "+i+" значение LAC");
- station.LAC = input.next();
- System.out.println("Введите "+i+" значение CID");
- station.CID = input.next();
- System.out.println("Введите "+i+" значение Rxl");
- station.Rxl = input.nextInt();
- //getYandexCoord();
- } // Заполняем массивы первоначальными данными, введёнными с клавиатуры
- for(int k = 0; k < Size; k++){
- double a = Rxl[k];
- a = a/20;
- Rxl[k] = a;
- double b = Math.pow((double) 10, a);
- Wn[k] = b;
- WnSum += Wn[k];
- } //Вычисляет W(n) и их сумму
- for(int i = 0; i < Wn.length & i < BaseLatitude.length; i++){
- double a = BaseLatitude[i];
- double b = BaseLongitude[i];
- double c = Wn[i];
- double[] WnLat = new double[Wn.length];
- double[] WnLong = new double[Wn.length];
- double d = a*c;
- double e = b*c;
- WnLat[i] = d;
- WnLong[i] = e;
- for(int x = 0; x < WnLat.length; x++){
- WnLatSum += WnLat[x];
- WnLongSum += WnLong[x];
- } //Вычисляет сумму массивов WnLat и WnLong
- SearchPointLatitude = WnLatSum/WnSum;
- SearchPointLongitude = WnLongSum/WnSum;
- } //Вычисляет "широту" и "долготу" искомой точки
- try (FileWriter writer = new FileWriter("Object`s Coords.txt", false)){
- writer.write("Latitude: "+SearchPointLatitude+" & "+"Longitude: "+SearchPointLongitude);
- writer.append('\n');
- writer.flush();
- } //Записывает расчитанные координаты объекта в файл
- catch (IOException ex){
- System.out.println(ex.getMessage());
- }
- theEnd();
- }
- private static void theEnd(){
- System.out.print("The End. Результат записан в файл.");
- } //Метод просто показывающий, что прога отработала, всё посчитала и записала результат в файл
- public static String getYandexCoord(String MCC, String MNC, String LAC, String CID) {
- String res="";
- try {
- URLConnection connection = new URL("http://mobile.maps.yandex.net/cellid_location/?&cellid="+Integer.parseInt(CID,16)
- +"&operatorid="+Integer.parseInt(MNC)+"&countrycode="+Integer.parseInt(MCC)+"&lac="+Integer.parseInt(LAC,16)).openConnection();
- BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- String line;
- StringBuilder sb = new StringBuilder();
- while((line = br.readLine())!=null) {
- sb.append(line);
- }
- int begin = sb.toString().indexOf("latitude")+10;
- int end = sb.toString().indexOf(" ", begin)-1;
- res=sb.toString().substring(begin,end)+" ";
- begin = sb.toString().indexOf("longitude")+11;
- end = sb.toString().indexOf(" ", begin)-1;
- res+=sb.toString().substring(begin,end);
- } catch (IOException e) {
- System.out.println(e);
- }
- return res;
- } //Получает координату БС по Яндексу
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement