@pieromqwerty/

APCSA Lab 4

Java

No description

fork
loading
Files
  • Main.java
  • MessageCategory.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.util.Scanner; // import the Scanner class
import java.util.*; 

public class Main {  
	public static boolean checkLoc(double lat, double lng) {
		double south = 39.882343;
		double north = 40.231315;
		double west = -105.743511;
		double east = -104.907864;
		boolean isInRange;
		
		if (lat >= south && lat <= north && lng >= west && lng <= north) {
			isInRange = true;
		}
		else {
			isInRange = false;
		}
		return isInRange;
	}

/*	
	public static String findCat(String str, String value) {
		int i = 0;
		int x = 0;
		String cats[] = {"fire", "smoke", "need", "offer", "structure", "road", "photo"};
		while (x = 0 && i < 7) {
			try {
				str.indexOf(cats[i]);
			}
			catch (Exception e) {
				i = i + 1;
			}
			if (i > 6) {
				
			}
		}
		try {
			int posOfSubstrTyp = str.indexOf(subStrTyp) + 5;
		}
		catch (Exception e) {}
	}
*/

	public static void main(String[] args) {  
		System.out.println(checkLoc(40.0, -105.0));
		boolean isInRange;
		String catString;
		String payload;
		MessageCategory category;
		category = MessageCategory.UNKNOWN;
		System.out.println(category);
		String str = "offer 40.022 -105.226 free essential supplies 4 evacs pets, 2323 55th st, boulder";
		
		String subStrTyp = "#typ";
		String subStrDet = "#det";
		String subStrLoc = "#loc";
		String subStrLat = "#lat";
		String subStrLng = "#lng";
		String subStrEnd = ";";
		int posOfSubstrTyp = str.indexOf(subStrTyp) + 5;
		int posOfSubstrEndTyp = str.indexOf(subStrEnd);
		int posOfSubstrDet = str.indexOf(subStrDet) + 5;
		int posOfSubstrEndDet = str.indexOf(subStrEnd, posOfSubstrEndTyp+1);
		int posOfSubstrLoc = str.indexOf(subStrLoc) + 5;
		int posOfSubstrEndLoc = str.indexOf(subStrEnd, posOfSubstrEndDet+1);
		int posOfSubstrLat = str.indexOf(subStrLat) + 5;
		int posOfSubstrEndLat = str.indexOf(subStrEnd, posOfSubstrEndLoc+1);
		int posOfSubstLng = str.indexOf(subStrLng) + 5;
		int posOfSubstrEndLng = str.indexOf(subStrEnd, posOfSubstrEndLat+1);
		String typ = str.substring(posOfSubstrTyp, posOfSubstrEndTyp);
		String det = str.substring(posOfSubstrDet, posOfSubstrEndDet);
		String loc = str.substring(posOfSubstrLoc, posOfSubstrEndLoc);
		String lat = str.substring(posOfSubstrLat, posOfSubstrEndLat);
		String lng = str.substring(posOfSubstLng, posOfSubstrEndLng);
		System.out.println("Type: " + typ);
		System.out.println("Details: " + det);
		System.out.println("Location: " + loc);
		System.out.println("Latitude: " + lat);
		System.out.println("Longitude: " + lng);
	}
}