Question
So I need to parse tweets with the String class and I have no idea what should I do for this lab and how to
So I need to parse tweets with the String class and I have no idea what should I do for this lab and how to start my coding. It will be nice if anyone guide me what should I do exactly and how I start this lab. Use the Scanner class (as discussed in lecture) to read in a tweet entered by the user and store it in a String variable named tweet. You will be splitting up (parsing) the information in the tweet into the 5 different types of information specified by the hashtags (type, location, detail, latitude, & longitude). Declare variables to store each of these pieces of information. Be sure to give these variables the appropriate data types and meaningful names. Now you actually need to divide the information in the tweet into the separate substrings of information. Declare 2 variables (start and finish) to hold the indices of where each substring starts and finishes. Once you have numbers assigned to start and finish, we want to discard the #tag and extract only the value. We know that the ; is where the value finishes but we need to find the index where the actual value begins. Hint: our start variable currently points to the index of the # and we know that all hashtag identifiers have the format, hashtag, 3 letters, and a space. Can we do simple math here to figure out the starting position of our value? Once we have the correct starting and ending positions for the value, we want to extract the substring at those positions and assign it to the appropriate variable declared in step 3. The trim() method removes leading and trailing white spaces (if any) from a String. Use the trim() method on each resultant String. Hint: The trim() method returns a modified String, but does not alter the String object that calls it. Ensure you are (re-)assigning a String to the result of trim(). After extracting the value encoded by each hashtag, we discard that part of the tweet String we are finished with it and are ready to repeat these steps for the next hashtag. We can use the substring method to extract the substring of our tweet variable starting where the last hashtag finished ( Hint: we know it finishes at a semicolon and we have that index stored in our finish variable, and we want to start right after that semicolon Also, remember that if we pass the substring method only 1 value, it begins at that index and goes until the end of the String). The type values come from a very small set of values, and we want to make them all caps. To do this, use the toUpperCase method of the String class. We also want to ensure that the detail and location values are free of commas (which might pose an obstacle to further processing). Use the replace method of the String class to do this. Replace each comma with a single hyphen (-). Now use System.out and print or println statements to produce formatted output, as shown in the included examples. HINT: Use the escape sequence \t to include tabs as needed For example, if input is "#typ offer; #det free essential supplies 4 evacs pets.; #loc 2323 55th st, boulder; #lat 40.022; #lng -105.226;" The output should be like this : Type: OFFER Detail: free essential supplies 4 evacs pets. Location: 2323 55th st- boulder Latitude: 40.022 Longitude: -105.226
****without using the split method
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started