Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

- At the top of your source file, include a comment stating the java program purpose -Use the Scanner class (as discussed in lecture) to

- At the top of your source file, include a comment stating the java program purpose -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. Hint: Using the Scanner class involves 1) importing a package, 2) creating a Scanner object, and 3) using the appropriate method to read in a whole line of text. -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. Hint: Each substring starts with a hashtag and finishes with a semicolon ( Is there a String class method that you can use to get the index of #typ or a ; ?) #typ value; #det value; #loc value; #lat value; #lng value; finish - 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(). Example String original = " text here "; String trimmed = original.trim(); //trimmed contains "text here" //At this point, the original string still contains -- " text here "

- 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.

Test your code with these. 1. "#typ offer; #det free essential supplies 4 evacs pets.; #loc 2323 55th st, boulder; #lat 40.022; #lng -105.226;" 2. "#typ structure; #det damaged; #loc 224 left fork road (shed) (house okay); #lat 40.029854; #lng -105.391055;" 3. "#typ wind; #det just switched, and now the smoke is thick around our house; #loc 40.352,-105.2045; #lat 40.3523; #lng - 105.2045;" 4. "#typ fire; #det firefighter sees a glow; #loc sw from west coach rd toward sunshine canyon; #lat 40.0515; #lng -105.332;" 5. "#typ structure; #det damaged; #loc unknown number, by 204 gold run road; #lat 40.050904; #lng -105.373941;" 6. "#typ evac; #det overflow shltr 4 evacuees at; #loc walt clark middle school, loveland; #lat 40.383; #lng -105.113;" 7. "#typ no fire; #det activity; #loc west of the pinewood res dam; #lat 40.367; #lng -105.292;" 8. "#typ photo; #det local wild horse; #loc wild horse; #lat 40.052304; #lng -105.319374;" 9. "#typ smoke; #det its raining ash; #loc windsor, co; #lat 40.499812; #lng -105.012075;"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions

Question

The company openly shares plans and information with employees.

Answered: 1 week ago