Question: With the following code below...I need help with the following questions. Written in the programming language java with comments explaining the code methods and meaning.

With the following code below...I need help with the following questions. Written in the programming language java with comments explaining the code methods and meaning.

  • The search you did in your previous work should now include a memory. The previously searched words are "robots", "fitness", and "wearable". Initially, I printed out the searched keywords clode_date and funds_raised_percent. Now, I need help including what's shown below.
  • Memory means that it keeps track of what has been searched. In simple words, you need to store inputs that we give to the search.
  • This means the search criteria and timestamp, should be stored in a collection.
  • There should be a method to call and print the number of search terms, their timestamps, and frequency

import org.json.JSONException; import org.json.JSONObject; import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; /**

* * The purpose of this assignment is to merge multiple single files into a single file. Then within * the merged file, search for the provided keywords and print out its close_date and * funds_raised_percent. */ public class MyFileMerger { // constants static final String mergeFilePath = "mergedFile.json"; static final String filePath1 = "file1.json"; static final String filePath2 = "file2.json"; static final String filePath3 = "file3.json"; public static void main(String[] args) throws IOException { // reading from the three given files and writing them into the merged file newFileReaderAndWriter(filePath1); newFileReaderAndWriter(filePath2); newFileReaderAndWriter(filePath3); // searching for the provided keywords in the merged file searchKeywords(); } /** * This method is reading the content from multiple and writing the content to the file that needs * to be merged * @param fileNamePath represents the main method to read the file from */ private static void newFileReaderAndWriter(String fileNamePath) throws IOException { // initializing the br variable // initializing the bw variable try (BufferedWriter bw = new BufferedWriter(new FileWriter(mergeFilePath, true)); BufferedReader br = new BufferedReader(new FileReader(fileNamePath))) { // creation of the BufferWriter object // set append to true with the new filewriter file // creation of the BufferReader object // the fileNamePath with the filereader object // creating a new variable with the value of an empty string String line; // using the while loop to check the content from the file while ((line = br.readLine()) != null) { bw.write(line + " "); } // catch handle exception } catch (FileNotFoundException e) { e.printStackTrace(); // print the exception details } // the finally block always executes } /** * This method is reading the content of the merged text file and then searching for the keywords */ private static void searchKeywords() throws IOException { // initializing the br variable BufferedReader br = null; // using the try/catch method to handle the exceptions try { // creating a new variable with the value of an empty string String content; // creation of the BufferReader object br = new BufferedReader(new FileReader(mergeFilePath)); // using the while loop to check the content from the file while ((content = br.readLine()) != null) { // passing each line of the searched content keywordsSearch(content); } } catch (FileNotFoundException e) { e.printStackTrace(); } finally { // the finally block always executes if(br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } } /** * This method is being used to search for the keywords in each line using the regex method * @param line represents the given keywords that need to be searched in each line */ private static void keywordsSearch (String line) { // list object List keywords = new ArrayList<>(); // add the keywords to the list // then compile the keywords to create pattern using compile() method keywords.add(Pattern.compile("robots")); keywords.add(Pattern.compile("fitness")); keywords.add(Pattern.compile("wearable")); // using the for loop to check whether the keywords match for(Pattern p: keywords) { // get a matcher object Matcher m = p.matcher(line); // using the .find method to search for the specific pattern if (m.find()) { stringToJsonObj(line); } } } /** * This method is going to convert string to json * * @param line represents the keywords that match previous method **/ private static void stringToJsonObj(String line) { try { // creation of a new json object JSONObject js = new JSONObject(line); JSONObject data = js.getJSONObject("data"); double funds_raised_percent = data.getDouble("funds_raised_percent"); // print out funds_raised_percent System.out.println("funds_raised_percent: " + funds_raised_percent); // used optString instead of getSting because I wasn't sure whether the data was missing String close_date = data.optString("close_date"); // print out close_date System.out.println("close_date: " + close_date); } catch (JSONException e){ e.printStackTrace(); } } }

I also provided an image of the JSON file. So if either of the keywords from the code is present in the array, then it should print the category, close_date, funds_raised_percent, and the tag_line

{"table_id":"Indiegogo","robot_id":"Indiegogo","run_id":"Indiegogo_2022-04-22T20_40_43_976Z","data":{"bullet_point":null,"category":"Wellness","category_url":"/explore/wellness","clickthrough_url":"/projects/perspective-bands-a-purpose-driven-watch","close_date":"2022-06-20T23:59:59-07:00","currency":"USD","funds_raised_amount":1500,"funds_raised_percent":0.01,"image_url":"https://c1.iggcdn.com/indiegogo-media-prod-cld/image/upload/c_fill,f_auto,h_273,w_273/bkglmcuonnsqymzkfckg.jpg","is_indemand":false,"is_pre_launch":false,"is_proven":false,"offered_by":null,"open_date":"2022-04-21T00:00:00-07:00","perk_goal_percentage":null,"perks_claimed":null,"price_offered":null,"price_retail":null,"product_stage":null,"project_id":2747820,"project_type":"campaign","tagline":"What is your \"Why\"? Dirac Links directly connects you to what matters most.","tags":["apps","smart watches","students","iot","founders of color"],"title":"Perspective Bands...A Purpose Driven Watch.","source_url":"https://www.indiegogo.com/explore/all?project_type=campaign&project_timing=all&sort=trending"}} {"table_id":"Indiegogo","robot_id":"Indiegogo","run_id":"Indiegogo_2022-04-22T20_40_43_976Z","data":{"bullet_point":null,"category":"Wellness","category_url":"/explore/wellness","clickthrough_url":"/projects/pain-how-to-find-it-feel-it-fix-it","close_date":"2022-06-10T23:59:59-07:00","currency":"CAD","funds_raised_amount":1254,"funds_raised_percent":0.0627,"image_url":"https://c1.iggcdn.com/indiegogo-media-prod-cld/image/upload/c_fill,f_auto,h_273,w_273/jxio2kf6hbe23hk3li8l.jpg","is_indemand":false,"is_pre_launch":false,"is_proven":false,"offered_by":null,"open_date":"2022-04-11T00:00:00-07:00","perk_goal_percentage":null,"perks_claimed":null,"price_offered":null,"price_retail":null,"product_stage":null,"project_id":2741173,"project_type":"campaign","tagline":"Find the Right Spot & Apply Precision Pressure to Improve Blood Flow, the Water of Life.","tags":["sports","mobile apps","trackers","kids"],"title":"Pain how to Find it, Feel it, & Fix it.","source_url":"https://www.indiegogo.com/explore/all?project_type=campaign&project_timing=all&sort=trending"}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!