OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * To change this license header, choose License Headers in Project Properties. |
| 3 * To change this template file, choose Tools | Templates |
| 4 * and open the template in the editor. |
| 5 */ |
| 6 |
| 7 /** |
| 8 * |
| 9 * @author biwen |
| 10 */ |
| 11 import java.io.File; |
| 12 import java.io.IOException; |
| 13 import java.util.Scanner; |
| 14 |
| 15 import org.apache.commons.io.FileUtils; |
| 16 import org.json.JSONException; |
| 17 import org.json.JSONObject; |
| 18 import org.json.JSONArray; |
| 19 |
| 20 |
| 21 |
| 22 |
| 23 public class ReadJson { |
| 24 ···· |
| 25 ···· |
| 26 ···· |
| 27 ···· |
| 28 public static void main(String[] args) throws IOException, JSONException { |
| 29 // Reading from System.in |
| 30 double ax; |
| 31 double ox; |
| 32 double ay = 0; |
| 33 double oy = 0; |
| 34 double az = 0; |
| 35 double oz = 0; |
| 36 ········ |
| 37 File file = new File (ReadJson.class.getResource("/Uunet.json").getFile(
)); |
| 38 ········ |
| 39 String content=FileUtils.readFileToString(file); |
| 40 JSONObject jsonObject = new JSONObject(content); |
| 41 JSONArray nodes = jsonObject.getJSONArray("nodes"); |
| 42 System.out.println("please enter first three hops of you original path "
); |
| 43 Scanner reader = new Scanner(System.in); |
| 44 System.out.println("Enter hopa: "); |
| 45 String x = reader.nextLine(); |
| 46 System.out.println("Enter hopb "); |
| 47 String y = reader.nextLine(); |
| 48 System.out.println("Enter hopc "); |
| 49 String z = reader.nextLine(); |
| 50 ········ |
| 51 Scanner in = new Scanner(System.in); |
| 52 reader.close(); |
| 53 ········ |
| 54 for (int index = 0; index < nodes.length(); ++index) |
| 55 { |
| 56 JSONObject node = nodes.getJSONObject(index); |
| 57 ············ |
| 58 ············ |
| 59 ············ |
| 60 if(node.getString("id") == null ? x == null : node.getString("id").e
quals(x)){ |
| 61 ················ |
| 62 String lonx = node.getString("Longitude"); |
| 63 String lanx =node.getString("Latitude"); |
| 64 System.out.println(lonx); |
| 65 System.out.println(lanx); |
| 66 ················ |
| 67 ax= Double.parseDouble(lanx); |
| 68 ················ |
| 69 ox= Double.parseDouble(lonx); |
| 70 ················ |
| 71 } |
| 72 ············ |
| 73 ············ |
| 74 ············ |
| 75 else if (node.getString("id") == null ? y == null : node.getString("
id").equals(y)){ |
| 76 //if("Vancouver".equals(node.getString("id"))){ |
| 77 ················ |
| 78 String lony = node.getString("Longitude"); |
| 79 String lany = node.getString("Latitude"); |
| 80 ay= Double.parseDouble(lany); |
| 81 oy= Double.parseDouble(lony); |
| 82 System.out.println(lony); |
| 83 System.out.println(lany); |
| 84 ················ |
| 85 ················ |
| 86 ················ |
| 87 ················ |
| 88 } |
| 89 ············ |
| 90 ············ |
| 91 else if(node.getString("id") == null ? z == null : node.getString("i
d").equals(z)){ |
| 92 //if("Vancouver".equals(node.getString("id"))){ |
| 93 ················ |
| 94 String lonz = node.getString("Longitude"); |
| 95 oz= Double.parseDouble(lonz); |
| 96 String lanz = node.getString("Latitude"); |
| 97 az= Double.parseDouble(lanz); |
| 98 System.out.println(lonz); |
| 99 System.out.println(lanz); |
| 100 ················ |
| 101 ················ |
| 102 ················ |
| 103 ················ |
| 104 ················ |
| 105 } |
| 106 else{ |
| 107 System.out.println(); |
| 108 ················ |
| 109 } |
| 110 ············ |
| 111 ············ |
| 112 } |
| 113 ········ |
| 114 double lontitudenew= (oz/0.5 )+(oy * -0.5/0.5); |
| 115 double latitudenew= (az/0.5 )+ (ay * -0.5/0.5); |
| 116 ········ |
| 117 System.out.println(lontitudenew); |
| 118 System.out.println(latitudenew); |
| 119 ········ |
| 120 ········ |
| 121 //node0[Longitude] = node2[Longitude]/n + node3[Longitude]*(n-1)/n (1<n<
someting) |
| 122 ········ |
| 123 } |
| 124 ···· |
| 125 ···· |
| 126 ···· |
| 127 ···· |
| 128 ···· |
| 129 ···· |
| 130 } |
| 131 |
| 132 |
| 133 |
OLD | NEW |