Compare commits
	
		
			8 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 28dbdbf406 | |||
| 02a82cc89d | |||
| f73a8ba394 | |||
| dc698c3f88 | |||
| 8a37f15a13 | |||
| 223140f752 | |||
| 840dbecdea | |||
| 7b6b15d1d2 | 
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -10,3 +10,4 @@ | |||||||
| 
 | 
 | ||||||
| # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||||||
| hs_err_pid* | hs_err_pid* | ||||||
|  | /target/ | ||||||
|  | |||||||
							
								
								
									
										13
									
								
								.idea/libraries/Maven__org_jetbrains_annotations_17_0_0.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								.idea/libraries/Maven__org_jetbrains_annotations_17_0_0.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | |||||||
|  | <component name="libraryTable"> | ||||||
|  |   <library name="Maven: org.jetbrains:annotations:17.0.0"> | ||||||
|  |     <CLASSES> | ||||||
|  |       <root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/17.0.0/annotations-17.0.0.jar!/" /> | ||||||
|  |     </CLASSES> | ||||||
|  |     <JAVADOC> | ||||||
|  |       <root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/17.0.0/annotations-17.0.0-javadoc.jar!/" /> | ||||||
|  |     </JAVADOC> | ||||||
|  |     <SOURCES> | ||||||
|  |       <root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/17.0.0/annotations-17.0.0-sources.jar!/" /> | ||||||
|  |     </SOURCES> | ||||||
|  |   </library> | ||||||
|  | </component> | ||||||
							
								
								
									
										6
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								pom.xml
									
									
									
									
									
								
							| @ -28,6 +28,12 @@ | |||||||
| 	    <artifactId>joda-time</artifactId> | 	    <artifactId>joda-time</artifactId> | ||||||
| 	    <version>2.9.9</version> | 	    <version>2.9.9</version> | ||||||
| 	</dependency> | 	</dependency> | ||||||
|  |       <dependency> | ||||||
|  |           <groupId>org.jetbrains</groupId> | ||||||
|  |           <artifactId>annotations</artifactId> | ||||||
|  |           <version>RELEASE</version> | ||||||
|  |           <scope>compile</scope> | ||||||
|  |       </dependency> | ||||||
| 
 | 
 | ||||||
|   </dependencies> |   </dependencies> | ||||||
| </project> | </project> | ||||||
							
								
								
									
										8
									
								
								src/Debug.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/Debug.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | |||||||
|  | public class Debug { | ||||||
|  | 
 | ||||||
|  |     private static final String preFix = "[ Debug ] "; | ||||||
|  |     public  static void print(String msg){ | ||||||
|  |         System.out.print(preFix + msg); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -13,20 +13,33 @@ import org.json.simple.JSONArray; | |||||||
| import org.json.simple.JSONObject; | import org.json.simple.JSONObject; | ||||||
| 
 | 
 | ||||||
| public class Location { | public class Location { | ||||||
|  | 
 | ||||||
| 	private double latitude; | 	private double latitude; | ||||||
| 	private double longitude; | 	private double longitude; | ||||||
| 	private String city; | 	private String city; | ||||||
|  | 	private JSONObject jsonInfo; | ||||||
| 
 | 
 | ||||||
| 	public Location(double lat, double lon) { | 	/** | ||||||
|  | 	 * Manual location constructor | ||||||
|  | 	 * @param lat | ||||||
|  | 	 * @param lon | ||||||
|  | 	 * @param city | ||||||
|  | 	 */ | ||||||
|  | 	public Location(double lat, double lon, String city) { | ||||||
| 		latitude = lat; | 		latitude = lat; | ||||||
| 		longitude = lon; | 		longitude = lon; | ||||||
|         city = "Unknown"; |         this.city = city; | ||||||
| 		//city = cityBasedOnIP(); //API intansive |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * Initialize with automatic online info from (ip-api.com). | ||||||
|  | 	 */ | ||||||
| 	public Location() { | 	public Location() { | ||||||
| 		//city = cityBasedOnIP(); | 		jsonInfo = apiInformationObject(); | ||||||
|         city = "Unknown"; | 		this.city = jsonInfo.get(API_Keys.city.name()).toString(); | ||||||
|  | 		this.latitude = (double)jsonInfo.get(API_Keys.lat.name()); | ||||||
|  | 		this.longitude = (double)jsonInfo.get(API_Keys.lon.name()); | ||||||
|  | 
 | ||||||
|     } |     } | ||||||
| 	 | 	 | ||||||
| 	public double getLatitude() { | 	public double getLatitude() { | ||||||
| @ -54,6 +67,11 @@ public class Location { | |||||||
| 		this.longitude = lon; | 		this.longitude = lon; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * @deprecated | ||||||
|  | 	 * @return | ||||||
|  | 	 */ | ||||||
| 	public String cityBasedOnIP() { | 	public String cityBasedOnIP() { | ||||||
| 		String city = ""; | 		String city = ""; | ||||||
| 		try { | 		try { | ||||||
| @ -79,14 +97,13 @@ 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()); | ||||||
|                  } |                  } | ||||||
| 
 | 
 | ||||||
|              } |              } | ||||||
|              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()); | ||||||
| 					 |  | ||||||
| 			 } | 			 } | ||||||
| 		} | 		} | ||||||
| 		catch (MalformedURLException e) { | 		catch (MalformedURLException e) { | ||||||
| @ -103,4 +120,70 @@ public class Location { | |||||||
| 		} | 		} | ||||||
| 		return city; | 		return city; | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
|  | 	private JSONObject apiInformationObject(){ | ||||||
|  | 		JSONObject jsonObj = null; | ||||||
|  | 		try { | ||||||
|  | 
 | ||||||
|  | 			URL url = new URL("http://ip-api.com/json"); | ||||||
|  | 			HttpURLConnection con = (HttpURLConnection) url.openConnection(); | ||||||
|  | 			con.setRequestMethod("GET"); | ||||||
|  | 			con.setRequestProperty("Content-Type", "application/json"); | ||||||
|  | 			int status = con.getResponseCode(); | ||||||
|  | 			BufferedReader in = new BufferedReader( | ||||||
|  | 					new InputStreamReader(con.getInputStream())); | ||||||
|  | 			String inputLine; | ||||||
|  | 			StringBuffer content = new StringBuffer(); | ||||||
|  | 			while ((inputLine = in.readLine()) != null) { | ||||||
|  | 				content.append(inputLine); | ||||||
|  | 			} | ||||||
|  | 			in.close(); | ||||||
|  | 
 | ||||||
|  | 			JSONParser parser = new JSONParser(); | ||||||
|  | 			Object resultObject = parser.parse(content.toString()); | ||||||
|  | 
 | ||||||
|  | 			if (resultObject instanceof JSONArray) { | ||||||
|  | 				JSONArray array=(JSONArray)resultObject; | ||||||
|  | 				for (Object object : array) { | ||||||
|  | 					jsonObj =(JSONObject)object; | ||||||
|  | 				} | ||||||
|  | 
 | ||||||
|  | 			} | ||||||
|  | 			else if (resultObject instanceof JSONObject) { | ||||||
|  | 				jsonObj =(JSONObject)resultObject; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		catch (MalformedURLException e) { | ||||||
|  | 			e.printStackTrace(); | ||||||
|  | 		} | ||||||
|  | 		catch (ProtocolException e) { | ||||||
|  | 			e.printStackTrace(); | ||||||
|  | 		} | ||||||
|  | 		catch (IOException e) { | ||||||
|  | 			e.printStackTrace(); | ||||||
|  | 		} | ||||||
|  | 		catch (ParseException e) { | ||||||
|  | 			e.printStackTrace(); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		return jsonObj; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	private  enum API_Keys { | ||||||
|  | 		zip, | ||||||
|  | 		country, | ||||||
|  | 		city, | ||||||
|  | 		org, | ||||||
|  | 		timezone, | ||||||
|  | 		isp, | ||||||
|  | 		quary, | ||||||
|  | 		regionName, | ||||||
|  | 		lon, | ||||||
|  | 		lat, | ||||||
|  | 		as, | ||||||
|  | 		countryCode, | ||||||
|  | 		region, | ||||||
|  | 		status | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -10,68 +10,12 @@ import org.joda.time.LocalDate; | |||||||
| //TODO: save Persons as list (databse)  | //TODO: save Persons as list (databse)  | ||||||
| public class Main { | public class Main { | ||||||
| 
 | 
 | ||||||
| 
 | 	/** | ||||||
|  | 	 * Main Entry point of Application. | ||||||
|  | 	 * @param args | ||||||
|  | 	 */ | ||||||
| 	public static void main(String[] args) { | 	public static void main(String[] args) { | ||||||
| 		Person p = new Person(12345, "Hesham", Level.BA); | 		Questions.run(); | ||||||
| 		System.out.println("-------------------------------------------------"); |  | ||||||
| 		Scanner in = new Scanner(System.in); |  | ||||||
| 		System.out.print("Name: "); |  | ||||||
| 		p.getAccount().setName(in.nextLine()); |  | ||||||
| 		System.out.print("ID: "); |  | ||||||
| 		p.getAccount().setID(in.nextInt()); |  | ||||||
| 		System.out.print("Account Type (Cheking, Investing, Saving): "); |  | ||||||
| 		p.getAccount().setAccountType(parseType(in.next())); |  | ||||||
| 		System.out.print("School: "); |  | ||||||
| 		p.getEdu().setSchool(in.next()); |  | ||||||
| 		System.out.print("Major: "); |  | ||||||
| 		p.getEdu().setMajor(in.next()); |  | ||||||
| 		List<Course> list = Arrays.asList(Course.EE201, Course.EE250,Course.ISLS201); |  | ||||||
| 		p.getEdu().addCourses(list); |  | ||||||
| 		Print(p); |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	/** |  | ||||||
| 	 * Finds the correct enum value of the parameter. |  | ||||||
| 	 * @param a string naming the account type |  | ||||||
| 	 * @return AccountType |  | ||||||
| 	 * @since 0.1 |  | ||||||
| 	 * @exception IncorrectStringException |  | ||||||
| 	 */ |  | ||||||
| 	private static AccountType parseType(String input) { |  | ||||||
| 		switch(input) { |  | ||||||
| 			case "Investing": |  | ||||||
| 				return AccountType.Investing; |  | ||||||
| 			case "Saving": |  | ||||||
| 				return AccountType.Saving; |  | ||||||
| 			default: |  | ||||||
| 				return AccountType.Checking; |  | ||||||
| 		} |  | ||||||
| 				 |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	/** |  | ||||||
| 	 * Standered print of Person's information |  | ||||||
| 	 * @param Person Object. |  | ||||||
| 	 * @since 0.1 |  | ||||||
| 	 */ |  | ||||||
| 	public static void Print(Person p) { |  | ||||||
| 		LocalDate date = new LocalDate(); |  | ||||||
| 
 |  | ||||||
| 		System.out.println( |  | ||||||
| 					"\n\n\n\t---------INFO---------\n" |  | ||||||
| 				 + "\t  --- "+ date.toString()+" ---\n" |  | ||||||
| 		         + "\tName: "+p.getAccount().getName()+"\n" |  | ||||||
| 		         + "\tID: "+p.getAccount().getID()+"\n" |  | ||||||
| 		         + "\tMajor: "+p.getEdu().getMajor()+"\n" |  | ||||||
| 		         + "\tSchool: "+p.getEdu().getSchool()+"\n" |  | ||||||
| 		         + "\tCity: "+p.getLocation().cityBasedOnIP()+"\n" |  | ||||||
| 				 + "\tAccountType: "+p.getAccount().getAccountType()+"\n" |  | ||||||
| 				 + "\t---------COURSES---------"); |  | ||||||
| 		int i = 1; |  | ||||||
| 		for (Course course : p.getEdu().getCourses()) { |  | ||||||
| 			System.out.println("\tCourse "+i+": "+course.name()); |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		 | 		 | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ public class Person { | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     public Person(int ID, String name, Level lvl) { |     public Person(int ID, String name, Level lvl) { | ||||||
| 		account = new Account(name,ID); |         account = new Account(name, ID); | ||||||
|         edu = new Education(null, null, lvl); |         edu = new Education(null, null, lvl); | ||||||
|         car = new Car(); |         car = new Car(); | ||||||
|         location = new Location(); |         location = new Location(); | ||||||
| @ -27,6 +27,10 @@ public class Person { | |||||||
|         return car; |         return car; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public void setCar(Car car) { | ||||||
|  |         this.car = car; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public String getName() { |     public String getName() { | ||||||
|         return name; |         return name; | ||||||
|     } |     } | ||||||
| @ -43,22 +47,16 @@ public class Person { | |||||||
|         this.location = location; |         this.location = location; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 	public void setCar(Car car) { |  | ||||||
| 		this.car = car; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
|     public boolean hasCar() { |     public boolean hasCar() { | ||||||
| 		if (car.getMake() != null) { |         return car.getMake() != null; | ||||||
| 			return true; |  | ||||||
| 		} |  | ||||||
| 		else return false; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public boolean isPHD() { |     public boolean isPHD() { | ||||||
| 		if (this.edu.getLevel() == Level.PHD) { |         return this.edu.getLevel() == Level.PHD; | ||||||
| 			return true; |  | ||||||
|     } |     } | ||||||
| 		else return false; | 
 | ||||||
|  |     public String getCity(){ | ||||||
|  |         return location.getCity(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										94
									
								
								src/Questions.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								src/Questions.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,94 @@ | |||||||
|  | import java.util.Arrays; | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.Scanner; | ||||||
|  | 
 | ||||||
|  | import org.joda.time.LocalDate; | ||||||
|  | 
 | ||||||
|  |  class Questions { | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	public static void run(){ | ||||||
|  | 
 | ||||||
|  | 		try { | ||||||
|  | 			Person p = new Person(12345, "Hesham", Level.BA); | ||||||
|  | 			System.out.println("-------------------------------------------------"); | ||||||
|  | 			Scanner in = new Scanner(System.in); | ||||||
|  | 			p.getAccount().setName(askForName(in)); | ||||||
|  | 			System.out.print("ID: "); | ||||||
|  | 			p.getAccount().setID(in.nextInt()); | ||||||
|  | 			System.out.print("Account Type (Cheking, Investing, Saving): "); | ||||||
|  | 			p.getAccount().setAccountType(parseType(in.next())); | ||||||
|  | 			System.out.print("School: "); | ||||||
|  | 			p.getEdu().setSchool(in.next()); | ||||||
|  | 			System.out.print("Major: "); | ||||||
|  | 			p.getEdu().setMajor(in.next()); | ||||||
|  | 			in.close(); | ||||||
|  | 			List<Course> 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) { | ||||||
|  | 		String name = null; | ||||||
|  | 		System.out.print("Name: "); | ||||||
|  | 		try { | ||||||
|  | 			name = in.nextLine(); | ||||||
|  | 		} | ||||||
|  | 		catch (Exception e) { | ||||||
|  | 			e.printStackTrace(); | ||||||
|  | 		} | ||||||
|  | 		return name; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * Standered print of Person's information | ||||||
|  | 	 * @param Person Object. | ||||||
|  | 	 * @since 0.1 | ||||||
|  | 	 */ | ||||||
|  | 	private static void Print(Person p) { | ||||||
|  | 		LocalDate date = new LocalDate(); | ||||||
|  | 
 | ||||||
|  | 		System.out.println( | ||||||
|  | 				"\n\n\n\t---------INFO---------\n" | ||||||
|  | 						+ "\t  --- "+ date.toString()+" ---\n" | ||||||
|  | 						+ "\tName: "+p.getAccount().getName()+"\n" | ||||||
|  | 						+ "\tID: "+p.getAccount().getID()+"\n" | ||||||
|  | 						+ "\tMajor: "+p.getEdu().getMajor()+"\n" | ||||||
|  | 						+ "\tSchool: "+p.getEdu().getSchool()+"\n" | ||||||
|  | 						+ "\tCity: "+p.getLocation().getCity()+"\n" | ||||||
|  | 						+	"\tLat: " + p.getLocation().getLatitude()+"\n" | ||||||
|  | 						+	"\tLon: " + p.getLocation().getLongitude()+"\n" | ||||||
|  | 
 | ||||||
|  | 						+ "\tAccountType: "+p.getAccount().getAccountType()+"\n" | ||||||
|  | 						+ "\t---------COURSES---------"); | ||||||
|  | 		int i = 1; | ||||||
|  | 		for (Course course : p.getEdu().getCourses()) { | ||||||
|  | 			System.out.println("\tCourse "+i+": "+course.name()); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * Finds the correct enum value of the parameter. | ||||||
|  | 	 * @param  string naming the account type | ||||||
|  | 	 * @return AccountType | ||||||
|  | 	 * @since 0.1 | ||||||
|  | 	 * @exception IncorrectStringException | ||||||
|  | 	 */ | ||||||
|  | 	private static AccountType parseType(String input) { | ||||||
|  | 		switch(input) { | ||||||
|  | 			case "Investing": | ||||||
|  | 				return AccountType.Investing; | ||||||
|  | 			case "Saving": | ||||||
|  | 				return AccountType.Saving; | ||||||
|  | 			default: | ||||||
|  | 				return AccountType.Checking; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user