Question: Edit this code so that instead of one big main method it is separated into different methods. _ _ _ _ _ _ _ _
Edit this code so that instead of one big main method it is separated into different methods.
import java.ioBufferedReader;
import java.ioInputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;
public class NamePopularityV
public static void mainString args
Scanner scanner new ScannerSystemin;
System.out.printEnter the year: ;
String year scanner.nextLine;
System.out.printEnter the name: ;
String name scanner.nextLine;
System.out.printEnter the gender MF: ;
String gender scanner.nextLinetoUpperCase;
String urlString "websiteurlgoeshere" year;
try
URL url new URLurlString;
HttpURLConnection connection HttpURLConnection url.openConnection;
connection.setRequestMethodGET;
if connectiongetResponseCode
BufferedReader reader new BufferedReadernew InputStreamReaderconnectiongetInputStream;
String line;
boolean found false;
while line reader.readLine null
String parts line.split;
if partslength
String recordName partstrim;
String recordGender partstrim;
String popularity partstrim;
if recordNameequalsIgnoreCasename && recordGender.equalsIgnoreCasegender
System.out.printlnThe popularity of the name name in year year is: popularity;
found true;
break;
reader.close;
if found
System.out.printlnThe name name with gender gender was not found for the year year ;
else
System.out.printlnFailed to fetch data. HTTP Response Code: connection.getResponseCode;
catch Exception e
System.out.printlnAn error occurred: egetMessage;
scanner.close;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
