Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am having trouble with this lab, I don't know how to start it. I inserted the lab below in images. This is the sample

I am having trouble with this lab, I don't know how to start it. I inserted the lab below in images.

This is the sample input:

Sample Input 1. smoke 40.499812 -105.012075 its raining ash 2. offer 40.022 -105.226 free essential supplies 4 evacs pets, 2323 55th st, boulder 3. structure 40.029854 -105.391055 damaged: 224 left fork road (shed) (house okay) 4. wind 40.3523 -105.2045 just switched, and now the smoke is thick around our house 5. fire 40.0515 -105.332 firefighter sees a glow: sw from west coach rd toward sunshine canyon 6. structure 40.050904 -105.373941 damaged: unknown number, by 204 gold run road 7. evac 40.383 -105.113 overflow shltr 4 evacuees at walt clark middle school, loveland 8. nofire 40.367 -105.292 activity: west of the pinewood res dam 9. photo 40.052304 -105.319374 local: wild horse 10. info 40.499812 -105.012075 its raining ash: windsor, co 11. need 40.011471 -105.28638 volunteers sun 8a-10p donation ctr 2 help w/donations for victims & firefighters: 3111 28th st 12. need 40.031131 -105.259259 people to help sort donations Sept 12 8am-9pm 3111 28th st 13. open 40.072208 -105.354437 evacuees can return to homes: lee hill 14. open 40.076431 -105.309757 lee hill dr.

Sample Output:

Please enter a formatted message: smoke 40.499812 -105.012075 its raining ash Category: ALERT Raw Cat: smoke Message: its raining ash Latitude: 40.499812 Longitude: -105.012075 In Range: false Please enter a formatted message: offer 40.022 -105.226 free essential supplies 4 evacs pets, 2323 55th st, boulder Category: OFFER Raw Cat: offer Message: free essential supplies 4 evacs pets, 2323 55th st, boulder Latitude: 40.022 Longitude: -105.226 In Range: true

Please enter a formatted message: structure 40.029854 -105.391055 damaged: 224 left fork road (shed) (house okay) Category: INFO Raw Cat: structure Message: damaged: 224 left fork road (shed) (house okay) Latitude: 40.029854 Longitude: -105.391055 In Range: true

image text in transcribed

image text in transcribed

image text in transcribed

Introduction This lab builds upon lab 3, using if-else and other branching statements to classify short messages (like tweets) based on keywords in the message. This is a task that might reasonably be done in real-world situations. E.g., certain tweets might contain information (e.g., a request for help, a fire sighted) that must be acted on quickly, and computer programs could be used to identify these based upon the text in the message. In this lab, you will create a Java enumeration called MessageCategory inside of classifyMessage that lists several message categories (NEED, OFFER, ALERT, INFO, UNKNOWN). Your program will parse the text of a user specified message, identify the category of the message, and assign this value to a variable (category) declared to be of type MessageCategory (only values from the enumeration can be assigned to the variable). You will also identify the latitude and longitude specified in the message and determine whether these are within ranges defined elsewhere in the program. Exercise - Using Enumerations and If Else statements Since the primary purpose of this lab is not String manipulation, we will use a simpler message format than that found in lab 3. You will still use the Scanner and String classes, however. You may assume that the messages processed by the program all have the following format: category latitude longitude payload where category is a single keyword indicating the message category (its type in Lab 3), latitude and longitude are both floating point numbers, and payload is a string of text (potentially containing arbitrary characters) constituting the primary body of the message. For instance, the message offer 40.022 -105.226 free essential supplies 4 evacs pets, 2323 55th st, boulder conforms to the above format. Additional sample messages are provided at the end of this document. You should use them to test your code. Instructions 1. Create a new class called ClassifyMessage (stored in a file called ClassifyMessage.java). 2. Declare the enumeration MessageCategory by adding the following line: enum MessageCategory (NEED, OFFER, ALERT, INFO, UNKNOWN) Where does this line of code belong? In the main method? In ClassifyMessage? Think about this You should declare the following variables in your program: o catString: String // The raw text of the message's category o payload: String 1 / The primary content of the message o latitude: double // The latitude indicated in the message o longitude: double // The longitude indicated in the message o isInRange: boolean // A "flag" indicating whether the latitude and // longitude values are within bounds o category: MessageCategory // The message's category 3. Additionally, you should declare the following double variables and initialize them to the shown values. These define geographic boundaries that the program uses. Some messages will originate from within those bounds, other messages will not. Is it a good idea to make these constants? O south double 39.882343 // southernmost latitude o north double 40.231315 // northernmost latitude Owest double -105.743511 // westernmost longitude o east double -104.907864 // easternmost longitude 4. After the variables have been declared, write a statement to prompt the user with the following message: Please enter a formatted message: 5. Use the keyboard object's next(), nextDouble(), and nextLine() methods to read in values for catString, latitude, longitude, and payload. You may assume that the message is entered as a single line of text and formatted as described earlier. 6. For payload and catString, if needed) you should trim (using the trim() method of the String class, if needed) any leading and trailing white spaces from the text. 7. Use a multi-branch if-else statement to match the value stored in catString to one of the elements of the enumeration MessageCategory. The conditions should be the following: o If the value of catString is one of "fire" or "smoke", then category should be assigned the value Message Category. ALERT. o Otherwise, if the value of catString is "need", then category should be assigned the value MessageCategory NEED. o Otherwise, if the value of catString is "offer", then category should be assigned the value MessageCategory. OFFER o Otherwise, if the value of catString is one of "structure", "road", "photo", or "evac", then category should be assigned the value MessageCategory.INFO. o Otherwise, category should be assigned the value MessageCategory. UNKNOWN When comparing the strings, you should use the equals IgnoreCase method. Why use the equals IgnoreCase method? Why not use ? 8. Use another if-else statement to determine whether the latitude and longitude specified in the message are within the geographic boundaries indicated by north, south, east, and west. Variable isInRange should be assigned the value true if and only if both of the below conditions are met. Otherwise, isInRange should be assigned the value false, CSCI 1301: Lab 4 Page 2 1. II. If latitude 2 south and latitude s north If longitude west and longitude seast Sample Input 1. Smoke 40.499812 -105.012075 its raining ash 2. offer 40.022 -105.226 free essential supplies 4 evacs pets, 2323 55th st, boulder structure 40.029854-105.391055 damaged: 224 left fork road (shed) (house okay) wind 40.3523 -105. 2045 just switched, and now the smoke is thick around our house fire 40.0515 -105.332 firefighter sees a glow: sw from west coach rd toward sunshine canyon structure 40.050904 -105.373941 damaged: unknown number, by 204 gold run road 7. evac 40.383 -105.113 overflow shitr 4 evacuees at walt clark middle school, loveland B. nofire 40.367 -105.292 activity: west of the pinewood res dam 9. photo 40.052304 -105.319374 local: wild horse 10. Inco 40.499812 -105.012075 its raining ash: windsor, co 11. need 40.011471 -105.28638 volunteers sun 8a-10p donation ctr 2 help w/donations for victims firefighters: 3111 28th st 12. need 40.031131 -105.259259 people to help sort donations Sept 12 Bam-9pe 3111 28th st 13. open 40.072208 -105.354437 evacuees can return to homes: lee hill 14. open 40.076431 -105,309757 lee hill dr. Sample Input and Output These are sample runs of the program. Input is indicated in red. Your input and output should be consistent with what is shown here except for the line longs of input or output (these long lines word wrap in this document, but in your program, these long lines of input or output should be on a single line) Please enter a formatted message: Snoke 48.499812 - 185.812975 its raining ash Category: ALERT Raw Cat: smoke Message: its rainine ash Latitude: 40.499812 Longitude: -105.012975 In Range: false CSCI 1301: Lab 4 Page 4 Please enter a formatted message: offer 40.822 -105.226 free essential supplies 4 evacs pets, 2323 55th st, boulder Category: OFFER Raw Cat: offer Message: free essential supplies 4 evacs pets, 2323 55th st, boulder Latitude: 40.022 Longitude: -105. 226 In Range: true Please enter a formatted message: structure 48.629854-185.391955 damaged: 224 left fork road (shed) (house okay) Category: INFO Raw Cat: structure Message: damaged: 224 left fork road (shed) (house okay) Latitude: 40.929854 Longitude: -195.391955 In Range: true Please enter a formatted message: wind 40.3523 -185.2845 just switched, and now the smoke is thick around our house Category: UNKNOWN Raw Cat: wind Message: just switched, and now the smoke is thick around our house Latitude: 40.3523 Loneitude: -105. 2045 In Range: false Please enter a formatted message: fire 40.8515 -105.332 firefighter sees a glow: sw from west coach rd toward sunshine canyon Category: ALERT Raw Cat: fire Message: firefighter sees a glow: sw from west coach rd toward sunshine canyon Latitude: 40.0515 Longitude: -105. 332 In Range: true Introduction This lab builds upon lab 3, using if-else and other branching statements to classify short messages (like tweets) based on keywords in the message. This is a task that might reasonably be done in real-world situations. E.g., certain tweets might contain information (e.g., a request for help, a fire sighted) that must be acted on quickly, and computer programs could be used to identify these based upon the text in the message. In this lab, you will create a Java enumeration called MessageCategory inside of classifyMessage that lists several message categories (NEED, OFFER, ALERT, INFO, UNKNOWN). Your program will parse the text of a user specified message, identify the category of the message, and assign this value to a variable (category) declared to be of type MessageCategory (only values from the enumeration can be assigned to the variable). You will also identify the latitude and longitude specified in the message and determine whether these are within ranges defined elsewhere in the program. Exercise - Using Enumerations and If Else statements Since the primary purpose of this lab is not String manipulation, we will use a simpler message format than that found in lab 3. You will still use the Scanner and String classes, however. You may assume that the messages processed by the program all have the following format: category latitude longitude payload where category is a single keyword indicating the message category (its type in Lab 3), latitude and longitude are both floating point numbers, and payload is a string of text (potentially containing arbitrary characters) constituting the primary body of the message. For instance, the message offer 40.022 -105.226 free essential supplies 4 evacs pets, 2323 55th st, boulder conforms to the above format. Additional sample messages are provided at the end of this document. You should use them to test your code. Instructions 1. Create a new class called ClassifyMessage (stored in a file called ClassifyMessage.java). 2. Declare the enumeration MessageCategory by adding the following line: enum MessageCategory (NEED, OFFER, ALERT, INFO, UNKNOWN) Where does this line of code belong? In the main method? In ClassifyMessage? Think about this You should declare the following variables in your program: o catString: String // The raw text of the message's category o payload: String 1 / The primary content of the message o latitude: double // The latitude indicated in the message o longitude: double // The longitude indicated in the message o isInRange: boolean // A "flag" indicating whether the latitude and // longitude values are within bounds o category: MessageCategory // The message's category 3. Additionally, you should declare the following double variables and initialize them to the shown values. These define geographic boundaries that the program uses. Some messages will originate from within those bounds, other messages will not. Is it a good idea to make these constants? O south double 39.882343 // southernmost latitude o north double 40.231315 // northernmost latitude Owest double -105.743511 // westernmost longitude o east double -104.907864 // easternmost longitude 4. After the variables have been declared, write a statement to prompt the user with the following message: Please enter a formatted message: 5. Use the keyboard object's next(), nextDouble(), and nextLine() methods to read in values for catString, latitude, longitude, and payload. You may assume that the message is entered as a single line of text and formatted as described earlier. 6. For payload and catString, if needed) you should trim (using the trim() method of the String class, if needed) any leading and trailing white spaces from the text. 7. Use a multi-branch if-else statement to match the value stored in catString to one of the elements of the enumeration MessageCategory. The conditions should be the following: o If the value of catString is one of "fire" or "smoke", then category should be assigned the value Message Category. ALERT. o Otherwise, if the value of catString is "need", then category should be assigned the value MessageCategory NEED. o Otherwise, if the value of catString is "offer", then category should be assigned the value MessageCategory. OFFER o Otherwise, if the value of catString is one of "structure", "road", "photo", or "evac", then category should be assigned the value MessageCategory.INFO. o Otherwise, category should be assigned the value MessageCategory. UNKNOWN When comparing the strings, you should use the equals IgnoreCase method. Why use the equals IgnoreCase method? Why not use ? 8. Use another if-else statement to determine whether the latitude and longitude specified in the message are within the geographic boundaries indicated by north, south, east, and west. Variable isInRange should be assigned the value true if and only if both of the below conditions are met. Otherwise, isInRange should be assigned the value false, CSCI 1301: Lab 4 Page 2 1. II. If latitude 2 south and latitude s north If longitude west and longitude seast Sample Input 1. Smoke 40.499812 -105.012075 its raining ash 2. offer 40.022 -105.226 free essential supplies 4 evacs pets, 2323 55th st, boulder structure 40.029854-105.391055 damaged: 224 left fork road (shed) (house okay) wind 40.3523 -105. 2045 just switched, and now the smoke is thick around our house fire 40.0515 -105.332 firefighter sees a glow: sw from west coach rd toward sunshine canyon structure 40.050904 -105.373941 damaged: unknown number, by 204 gold run road 7. evac 40.383 -105.113 overflow shitr 4 evacuees at walt clark middle school, loveland B. nofire 40.367 -105.292 activity: west of the pinewood res dam 9. photo 40.052304 -105.319374 local: wild horse 10. Inco 40.499812 -105.012075 its raining ash: windsor, co 11. need 40.011471 -105.28638 volunteers sun 8a-10p donation ctr 2 help w/donations for victims firefighters: 3111 28th st 12. need 40.031131 -105.259259 people to help sort donations Sept 12 Bam-9pe 3111 28th st 13. open 40.072208 -105.354437 evacuees can return to homes: lee hill 14. open 40.076431 -105,309757 lee hill dr. Sample Input and Output These are sample runs of the program. Input is indicated in red. Your input and output should be consistent with what is shown here except for the line longs of input or output (these long lines word wrap in this document, but in your program, these long lines of input or output should be on a single line) Please enter a formatted message: Snoke 48.499812 - 185.812975 its raining ash Category: ALERT Raw Cat: smoke Message: its rainine ash Latitude: 40.499812 Longitude: -105.012975 In Range: false CSCI 1301: Lab 4 Page 4 Please enter a formatted message: offer 40.822 -105.226 free essential supplies 4 evacs pets, 2323 55th st, boulder Category: OFFER Raw Cat: offer Message: free essential supplies 4 evacs pets, 2323 55th st, boulder Latitude: 40.022 Longitude: -105. 226 In Range: true Please enter a formatted message: structure 48.629854-185.391955 damaged: 224 left fork road (shed) (house okay) Category: INFO Raw Cat: structure Message: damaged: 224 left fork road (shed) (house okay) Latitude: 40.929854 Longitude: -195.391955 In Range: true Please enter a formatted message: wind 40.3523 -185.2845 just switched, and now the smoke is thick around our house Category: UNKNOWN Raw Cat: wind Message: just switched, and now the smoke is thick around our house Latitude: 40.3523 Loneitude: -105. 2045 In Range: false Please enter a formatted message: fire 40.8515 -105.332 firefighter sees a glow: sw from west coach rd toward sunshine canyon Category: ALERT Raw Cat: fire Message: firefighter sees a glow: sw from west coach rd toward sunshine canyon Latitude: 40.0515 Longitude: -105. 332 In Range: true

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

Students also viewed these Databases questions