This commit is contained in:
hesham 2019-02-12 03:46:50 +03:00
parent 7b6b15d1d2
commit 840dbecdea
2 changed files with 33 additions and 5 deletions

View File

@ -16,6 +16,7 @@ public class Location {
private double latitude; private double latitude;
private double longitude; private double longitude;
private String city; private String city;
private String lastInfoString;
public Location(double lat, double lon) { public Location(double lat, double lon) {
latitude = lat; latitude = lat;
@ -79,13 +80,15 @@ public class Location {
JSONArray array=(JSONArray)resultObject; JSONArray array=(JSONArray)resultObject;
for (Object object : array) { for (Object object : array) {
JSONObject obj =(JSONObject)object; 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) { else if (resultObject instanceof JSONObject) {
JSONObject obj =(JSONObject)resultObject; JSONObject obj =(JSONObject)resultObject;
city = (String)obj.get("city"); city = (String)obj.get(API_Keys.city.name());
lastInfoString = (String)obj.toString();
} }
} }
@ -103,4 +106,22 @@ public class Location {
} }
return city; return city;
} }
private enum API_Keys {
zip,
country,
city,
org,
timezone,
isp,
quary,
regionName,
lon,
lat,
as,
countryCode,
region,
status
}
} }

View File

@ -9,6 +9,8 @@ public class Questions {
public static void run(){ public static void run(){
try {
Person p = new Person(12345, "Hesham", Level.BA); Person p = new Person(12345, "Hesham", Level.BA);
System.out.println("-------------------------------------------------"); System.out.println("-------------------------------------------------");
Scanner in = new Scanner(System.in); Scanner in = new Scanner(System.in);
@ -26,6 +28,11 @@ public class Questions {
p.getEdu().addCourses(list); p.getEdu().addCourses(list);
Print(p); Print(p);
} }
catch (Exception ex) {
System.out.print(" Error in input. \n");
ex.printStackTrace();
}
}
private static String askForName(Scanner in) { private static String askForName(Scanner in) {
String name = null; String name = null;
@ -65,7 +72,7 @@ public class Questions {
/** /**
* Finds the correct enum value of the parameter. * Finds the correct enum value of the parameter.
* @param a string naming the account type * @param string naming the account type
* @return AccountType * @return AccountType
* @since 0.1 * @since 0.1
* @exception IncorrectStringException * @exception IncorrectStringException