JAVA PROGRAM   Please Modify this program with further modifications as listed below: The program must pass the test case when uploaded to Hypergrade. ALSO, change the following in the program:  System.out.print("Enter a name (or 'QUIT' to exit): "); to: Enter a name to search or type QUIT to exit and take out this: System.out.println(filename + " is missing. Exiting..."); import java.io.*; import java.util.*; public class Main {     public static void main(String[] args) {         List girlsNames = loadNames("GirlNames.txt");         List boysNames = loadNames("BoyNames.txt");         Scanner scanner = new Scanner(System.in);         while (true) {             System.out.print("Enter a name (or 'QUIT' to exit): ");             String input = scanner.nextLine();             if (input.equalsIgnoreCase("QUIT")) {                 break;             }             searchAndDisplay(input, girlsNames, boysNames);         }         scanner.close();     }     private static List loadNames(String filename) {         List names = new ArrayList<>();         try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {             String line;             while ((line = reader.readLine()) != null) {                 names.add(line.trim());             }         } catch (IOException e) {             System.out.println(filename + " is missing. Exiting...");             System.exit(1); // Exit the program if a file is missing         }         return names;     }     private static void searchAndDisplay(String name, List girlsNames, List boysNames) {         int girlIndex = searchName(name, girlsNames);         int boyIndex = searchName(name, boysNames);         String capitalizedName = name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();         if (girlIndex == -1 && boyIndex == -1) {             System.out.println("The name '" + capitalizedName + "' was not found in either list.");         } else if (girlIndex != -1 && boyIndex == -1) {             System.out.println("The name '" + capitalizedName + "' was found in popular girl names list (line " + (girlIndex + 1) + ").");         } else if (girlIndex == -1 && boyIndex != -1) {             System.out.println("The name '" + capitalizedName + "' was found in popular boy names list (line " + (boyIndex + 1) + ").");         } else {             System.out.println("The name '" + capitalizedName + "' was found in both lists: boy names (line " + (boyIndex + 1) + ") and girl names (line " + (girlIndex + 1) + ").");         }     }     private static int searchName(String name, List namesList) {         for (int i = 0; i < namesList.size(); i++) {             if (namesList.get(i).equalsIgnoreCase(name)) {                 return i;             }         }         return -1;     } }   THE TEXT FILES ARE LOCATED IN HYPERGRADE I provided them and the failed test case as a screenshot. Thank you.  Test Case 1 Enter a name to search or type QUIT to exit:\n AnnabelleENTER The name 'Annabelle' was not found in either list.\n Enter a name to search or type QUIT to exit:\n xavierENTER The name 'Xavier' was found in popular boy names list (line 81).\n Enter a name to search or type QUIT to exit:\n AMANDAENTER The name 'Amanda' was found in popular girl names list (line 63).\n Enter a name to search or type QUIT to exit:\n jOrdAnENTER The name 'Jordan' was found in both lists: boy names (line 38) and girl names (line 75).\n Enter a name to search or type QUIT to exit:\n quitENTER

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%
JAVA PROGRAM
 
Please Modify this program with further modifications as listed below: The program must pass the test case when uploaded to Hypergrade. ALSO, change the following in the program: 

System.out.print("Enter a name (or 'QUIT' to exit): "); to: Enter a name to search or type QUIT to exit and take out this: System.out.println(filename + " is missing. Exiting...");

import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        List<String> girlsNames = loadNames("GirlNames.txt");
        List<String> boysNames = loadNames("BoyNames.txt");

        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.print("Enter a name (or 'QUIT' to exit): ");
            String input = scanner.nextLine();

            if (input.equalsIgnoreCase("QUIT")) {
                break;
            }

            searchAndDisplay(input, girlsNames, boysNames);
        }

        scanner.close();
    }

    private static List<String> loadNames(String filename) {
        List<String> names = new ArrayList<>();
        try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
            String line;
            while ((line = reader.readLine()) != null) {
                names.add(line.trim());
            }
        } catch (IOException e) {
            System.out.println(filename + " is missing. Exiting...");
            System.exit(1); // Exit the program if a file is missing
        }
        return names;
    }

    private static void searchAndDisplay(String name, List<String> girlsNames, List<String> boysNames) {
        int girlIndex = searchName(name, girlsNames);
        int boyIndex = searchName(name, boysNames);

        String capitalizedName = name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();

        if (girlIndex == -1 && boyIndex == -1) {
            System.out.println("The name '" + capitalizedName + "' was not found in either list.");
        } else if (girlIndex != -1 && boyIndex == -1) {
            System.out.println("The name '" + capitalizedName + "' was found in popular girl names list (line " + (girlIndex + 1) + ").");
        } else if (girlIndex == -1 && boyIndex != -1) {
            System.out.println("The name '" + capitalizedName + "' was found in popular boy names list (line " + (boyIndex + 1) + ").");
        } else {
            System.out.println("The name '" + capitalizedName + "' was found in both lists: boy names (line " + (boyIndex + 1) + ") and girl names (line " + (girlIndex + 1) + ").");
        }
    }

    private static int searchName(String name, List<String> namesList) {
        for (int i = 0; i < namesList.size(); i++) {
            if (namesList.get(i).equalsIgnoreCase(name)) {
                return i;
            }
        }
        return -1;
    }
}

 

THE TEXT FILES ARE LOCATED IN HYPERGRADE I provided them and the failed test case as a screenshot. Thank you. 

Test Case 1

Enter a name to search or type QUIT to exit:\n
AnnabelleENTER
The name 'Annabelle' was not found in either list.\n
Enter a name to search or type QUIT to exit:\n
xavierENTER
The name 'Xavier' was found in popular boy names list (line 81).\n
Enter a name to search or type QUIT to exit:\n
AMANDAENTER
The name 'Amanda' was found in popular girl names list (line 63).\n
Enter a name to search or type QUIT to exit:\n
jOrdAnENTER
The name 'Jordan' was found in both lists: boy names (line 38) and girl names (line 75).\n
Enter a name to search or type QUIT to exit:\n
quitENTER

 

Test Case 1 Failed Show what's missing
Enter a name to search or type QUIT to exit: \n
Annabelle ENTER
The name 'Annabelle' was not found in either list.\n
Enter a name to search or type QUIT to exit: \n
xavier ENTER
The name 'Xavier' was found in popular boy names list (line 81).\n
QUIT to exit: \n
Enter a name to search or type
AMANDA ENTER
The name 'Amanda' was found in
Enter a name to search or type
jordAn ENTER
popular girl names list (line 63). \n
QUIT to exit: \n
The name 'Jordan' was found in both lists: boy names (line 38) and girl names (line 75).\n
Enter a name to search or type QUIT to exit: \n
quit ENTER
Transcribed Image Text:Test Case 1 Failed Show what's missing Enter a name to search or type QUIT to exit: \n Annabelle ENTER The name 'Annabelle' was not found in either list.\n Enter a name to search or type QUIT to exit: \n xavier ENTER The name 'Xavier' was found in popular boy names list (line 81).\n QUIT to exit: \n Enter a name to search or type AMANDA ENTER The name 'Amanda' was found in Enter a name to search or type jordAn ENTER popular girl names list (line 63). \n QUIT to exit: \n The name 'Jordan' was found in both lists: boy names (line 38) and girl names (line 75).\n Enter a name to search or type QUIT to exit: \n quit ENTER
Test Case 1
Failed Show what's missing
||
Enter a name (or 'QUIT' to exit): Annabelle ENTER
The name 'Annabelle' was not found in either list.\n
Enter a name (or 'QUIT' to exit): xavier ENTER
The name Xavier' was found in popular boy names list (line 81). \n
Enter a name (or 'QUIT' to exit): AMANDA ENTER
The name 'Amanda' was found in popular girl names list (line 63).\n
Enter a name (or 'QUIT' to exit): j0rdAn ENTER
The name 'Jordan' was found in both lists: boy names (line 38) and girl names (line 75).\n
Enter a name (or 'QUIT' to exit): quit ENTER
Test Case 1 Failed Show what's missing
Enter a name to search or type QUIT to exit: \n
Annabelle ENTER
The name
Enter a name to search or type QUIT to exit: \n
xavier ENTER
Annabelle' was not found in either list.\n
The name 'Xavier' was found in popular boy names list (line 81). \n
QUIT to exit: \n
Enter a name to search or type
AMANDA ENTER
The name 'Amanda' was found in
Enter a name to search or type
jordAn ENTER
popular girl names list (line 63).\n
QUIT to exit: \n
The name 'Jordan' was found in both lists: boy names (line 38) and girl names (line 75).\n
Enter a name to search or type QUIT to exit: \n
quit ENTER
Transcribed Image Text:Test Case 1 Failed Show what's missing || Enter a name (or 'QUIT' to exit): Annabelle ENTER The name 'Annabelle' was not found in either list.\n Enter a name (or 'QUIT' to exit): xavier ENTER The name Xavier' was found in popular boy names list (line 81). \n Enter a name (or 'QUIT' to exit): AMANDA ENTER The name 'Amanda' was found in popular girl names list (line 63).\n Enter a name (or 'QUIT' to exit): j0rdAn ENTER The name 'Jordan' was found in both lists: boy names (line 38) and girl names (line 75).\n Enter a name (or 'QUIT' to exit): quit ENTER Test Case 1 Failed Show what's missing Enter a name to search or type QUIT to exit: \n Annabelle ENTER The name Enter a name to search or type QUIT to exit: \n xavier ENTER Annabelle' was not found in either list.\n The name 'Xavier' was found in popular boy names list (line 81). \n QUIT to exit: \n Enter a name to search or type AMANDA ENTER The name 'Amanda' was found in Enter a name to search or type jordAn ENTER popular girl names list (line 63).\n QUIT to exit: \n The name 'Jordan' was found in both lists: boy names (line 38) and girl names (line 75).\n Enter a name to search or type QUIT to exit: \n quit ENTER
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY