diff --git a/src/Location.java b/src/Location.java index 4da8d54..a65dfda 100644 --- a/src/Location.java +++ b/src/Location.java @@ -16,6 +16,7 @@ public class Location { private double latitude; private double longitude; private String city; + private String lastInfoString; public Location(double lat, double lon) { latitude = lat; @@ -79,15 +80,17 @@ public class Location { JSONArray array=(JSONArray)resultObject; for (Object object : array) { JSONObject obj =(JSONObject)object; - city = (String)obj.get("city"); + city = (String)obj.get(API_Keys.city.name()); + lastInfoString = (String)obj.toString(); } } else if (resultObject instanceof JSONObject) { JSONObject obj =(JSONObject)resultObject; - city = (String)obj.get("city"); - - } + city = (String)obj.get(API_Keys.city.name()); + lastInfoString = (String)obj.toString(); + + } } catch (MalformedURLException e) { e.printStackTrace(); @@ -103,4 +106,22 @@ public class Location { } return city; } + + + private enum API_Keys { + zip, + country, + city, + org, + timezone, + isp, + quary, + regionName, + lon, + lat, + as, + countryCode, + region, + status + } } diff --git a/src/Questions.java b/src/Questions.java index fa1ef76..502db3d 100644 --- a/src/Questions.java +++ b/src/Questions.java @@ -9,6 +9,8 @@ public class Questions { public static void run(){ + + try { Person p = new Person(12345, "Hesham", Level.BA); System.out.println("-------------------------------------------------"); Scanner in = new Scanner(System.in); @@ -25,6 +27,11 @@ public class Questions { List list = Arrays.asList(Course.EE201, Course.EE250,Course.ISLS201); p.getEdu().addCourses(list); Print(p); + } + catch (Exception ex) { + System.out.print(" Error in input. \n"); + ex.printStackTrace(); + } } private static String askForName(Scanner in) { @@ -65,7 +72,7 @@ public class Questions { /** * Finds the correct enum value of the parameter. - * @param a string naming the account type + * @param string naming the account type * @return AccountType * @since 0.1 * @exception IncorrectStringException