JAVA PROGRAM BELOW IS A WORKING PROGRAM. PLEASE MODIFY THIS PROGRAM SO IT PASSES THE TEST CASE. I HAVE PROVIDED THE failed part of the test case AND THE INPUTS AS A SCREENSHOT.  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     import java.io.*; import java.util.*; public class NameSearcher {     // Load a text file into a list of names (ignores case)     private static List loadFileToList(String filename) throws FileNotFoundException {         List namesList = new ArrayList<>();         File file = new File(filename);         // Check if the file exists, if not, throw an exception         if (!file.exists()) {             throw new FileNotFoundException(filename);         }         try (Scanner scanner = new Scanner(file)) {             while (scanner.hasNextLine()) {                 // Read each line, split by whitespace, and add names to the list in lowercase                 String line = scanner.nextLine().trim();                 String[] names = line.split("\\s+");                 for (String name : names) {                     namesList.add(name.toLowerCase());                 }             }         }         return namesList;     }     // Search for a name in a list and return its position (ignores case)     private static Integer searchNameInList(String name, List namesList) {         int index = namesList.indexOf(name.toLowerCase());         return index == -1 ? null : index + 1;     }     public static void main(String[] args) {         List boyNames;         List girlNames;         boolean boyFileExists = false;         boolean girlFileExists = false;         try {             // Load boy names from a file, set boyFileExists to true if successful             boyNames = loadFileToList("Boynames.txt");             boyFileExists = true;         } catch (FileNotFoundException e) {             // If the file is not found, initialize an empty list             boyNames = new ArrayList<>();         }         try {             // Load girl names from a file, set girlFileExists to true if successful             girlNames = loadFileToList("Girlnames.txt");             girlFileExists = true;         } catch (FileNotFoundException e) {             // If the file is not found, initialize an empty list             girlNames = new ArrayList<>();         }         Scanner scanner = new Scanner(System.in);         while (true) {             System.out.print("Enter a name to search or type QUIT to exit:\n");             String input = scanner.nextLine().trim();             if (input.equalsIgnoreCase("QUIT")) {                 break;             }             // Capitalize the first letter and lowercase the rest of the input             String capitalizedInput = input.substring(0, 1).toUpperCase() + input.substring(1).toLowerCase();             Integer boyIndex = searchNameInList(input, boyNames);             Integer girlIndex = searchNameInList(input, girlNames);             if (boyIndex == null && girlIndex == null) {                 // If the name is not found in either list                 System.out.println("The name '" + capitalizedInput + "' was not found in either list.");             } else {                 if (boyIndex != null && girlIndex != null) {                     // If the name is found in both lists                     System.out.println("The name '" + capitalizedInput + "' was found in both lists: boy names (line " + boyIndex + ") and girl names (line " + girlIndex + ").");                 } else if (boyIndex != null) {                     // If the name is found in the boy names list                     System.out.println("The name '" + capitalizedInput + "' was found in popular boy names list (line " + boyIndex + ").");                 } else {                     // If the name is found in the girl names list                     System.out.println("The name '" + capitalizedInput + "' was found in popular girl names list (line " + girlIndex + ").");                 }             }         }         scanner.close();     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

JAVA PROGRAM

BELOW IS A WORKING PROGRAM. PLEASE MODIFY THIS PROGRAM SO IT PASSES THE TEST CASE. I HAVE PROVIDED THE failed part of the test case AND THE INPUTS AS A SCREENSHOT. 

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
 
 

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

public class NameSearcher {

    // Load a text file into a list of names (ignores case)
    private static List<String> loadFileToList(String filename) throws FileNotFoundException {
        List<String> namesList = new ArrayList<>();
        File file = new File(filename);

        // Check if the file exists, if not, throw an exception
        if (!file.exists()) {
            throw new FileNotFoundException(filename);
        }

        try (Scanner scanner = new Scanner(file)) {
            while (scanner.hasNextLine()) {
                // Read each line, split by whitespace, and add names to the list in lowercase
                String line = scanner.nextLine().trim();
                String[] names = line.split("\\s+");
                for (String name : names) {
                    namesList.add(name.toLowerCase());
                }
            }
        }
        return namesList;
    }

    // Search for a name in a list and return its position (ignores case)
    private static Integer searchNameInList(String name, List<String> namesList) {
        int index = namesList.indexOf(name.toLowerCase());
        return index == -1 ? null : index + 1;
    }

    public static void main(String[] args) {
        List<String> boyNames;
        List<String> girlNames;

        boolean boyFileExists = false;
        boolean girlFileExists = false;

        try {
            // Load boy names from a file, set boyFileExists to true if successful
            boyNames = loadFileToList("Boynames.txt");
            boyFileExists = true;
        } catch (FileNotFoundException e) {
            // If the file is not found, initialize an empty list
            boyNames = new ArrayList<>();
        }

        try {
            // Load girl names from a file, set girlFileExists to true if successful
            girlNames = loadFileToList("Girlnames.txt");
            girlFileExists = true;
        } catch (FileNotFoundException e) {
            // If the file is not found, initialize an empty list
            girlNames = new ArrayList<>();
        }

        Scanner scanner = new Scanner(System.in);

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

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

            // Capitalize the first letter and lowercase the rest of the input
            String capitalizedInput = input.substring(0, 1).toUpperCase() + input.substring(1).toLowerCase();
            Integer boyIndex = searchNameInList(input, boyNames);
            Integer girlIndex = searchNameInList(input, girlNames);

            if (boyIndex == null && girlIndex == null) {
                // If the name is not found in either list
                System.out.println("The name '" + capitalizedInput + "' was not found in either list.");
            } else {
                if (boyIndex != null && girlIndex != null) {
                    // If the name is found in both lists
                    System.out.println("The name '" + capitalizedInput + "' was found in both lists: boy names (line " + boyIndex + ") and girl names (line " + girlIndex + ").");
                } else if (boyIndex != null) {
                    // If the name is found in the boy names list
                    System.out.println("The name '" + capitalizedInput + "' was found in popular boy names list (line " + boyIndex + ").");
                } else {
                    // If the name is found in the girl names list
                    System.out.println("The name '" + capitalizedInput + "' was found in popular girl names list (line " + girlIndex + ").");
                }
            }
        }
        scanner.close();
    }
}

L
8:34 S
BOYNAMES.TXT.jpg
Search
OT5GUC 57%
content://media/external/fil 5
Jacob Michael Joshua Matthew Daniel
Christopher Andrew Ethan Joseph William
Anthony David Alexander Nicholas Ryan
Tyler James John Jonathan Noah Brandon
Christian Dylan Samuel Benjamin Zachary
Nathan Logan Justin Gabriel Jose Austin
Kevin Elijah Caleb Robert Thomas Jordan
Cameron Jack Hunter Jackson Angel Isaiah
Evan Isaac Mason Luke Jason Gavin Jayden
Aaron Connor Aiden Aidan Kyle Juan Charles
Luis Adam Lucas Brian Eric Adrian Nathaniel
Sean Alex Carlos Bryan Ian Owen Jesus
Landon Julian Chase Cole Diego Jeremiah
Steven Sebastian Xavier Timothy Carter
Wyatt Brayden Blake Hayden Devin Cody
Richard Seth Dominic Jaden Antonio Miguel
Liam Patrick Carson Jesse Tristan Alejandro
Henry Victor Trevor Bryce Jake Riley Colin
Jared Jeremy Mark Caden Garrett Parker
Marcus Vincent Kaleb Kaden Brady Colton
Kenneth Joel Oscar Josiah Jorge Cooper
Ashton Tanner Eduardo Paul Edward Ivan
Preston Maxwell Alan Levi Stephen Grant
Nicolas Omar Dakota Alexis George Collin Eli
Spencer Gage Max Cristian Ricardo Derek
Micah Brody Francisco Nolan Ayden Dalton
Shane Peter Damian Jeffrey Brendan Travis
Fernando Peyton Conner Andres Javier
Giovanni Shawn Braden
Cesar Bradley
Emmanuel Manuel Edgar Erik Mario Edwin
Johnathan Devon Erick Wesley Oliver
Trenton Hector Malachi Jalen Raymond
Gregory Abraham Elias Leonardo Sergio
Donovan Colby Marco Bryson Martin
O
GIRLNAMES.TXT.jpg
Search
12:39 1
OT lll 50%
Emily Madison Emma Olivia Hannah Abigail
Isabella Samantha Elizabeth Ashley Alexis
Sarah Sophia Alyssa Grace Ava Taylor
Brianna Lauren Chloe Natalie Kayla Jessica
Anna Victoria Mia Hailey Sydney Jasmine
Julia Morgan Destiny Rachel Ella Kaitlyn
Megan Katherine Savannah Jennifer
Alexandra Allison Haley Maria Kaylee Lily
Makayla Brooke Mackenzie Nicole Addison
Stephanie Lillian Andrea Zoe Faith Kimberly
Madeline Alexa Katelyn Gabriella Gabrielle
Trinity Amanda Kylie Mary Paige Riley Jenna
Leah Sara Rebecca Michelle Sofia Vanessa
Jordan Angelina Caroline Avery Audrey
Evelyn Maya Claire Autumn Jocelyn Ariana
Nevaeh Arianna Jada Bailey Brooklyn
Aaliyah Amber Isabel Danielle Mariah
Melanie Sierra Erin Molly Amelia Isabelle
Madelyn Melissa Jacqueline Marissa Shelby
Angela Leslie Katie Jade Catherine Diana
Aubrey Mya Amy Briana Sophie Gabriela
Breanna Gianna Kennedy Gracie Peyton
Adriana Christina Courtney Daniela Kathryn
Lydia Valeria Layla Alexandria Natalia Angel
Laura Charlotte Margaret Cheyenne Mikayla
Miranda Naomi Kelsey Payton Ana Alicia
Jillian Daisy Mckenzie Ashlyn Caitlin Sabrina
Summer Ruby Rylee Valerie Skylar Lindsey
Kelly Genesis Zoey Eva Sadie Alexia Cassidy
Kylee Kendall Jordyn Kate Jayla Karen
Tiffany Cassandra Juliana Reagan Caitlyn
Giselle Serenity Alondra Lucy Kiara Bianca
Crystal Erica Angelica Hope Chelsea Alana
Liliana Brittany Camila Makenzie Veronica
Lilly Abby Jazmin Adrianna Karina Delaney
Ellie Jasmin
Transcribed Image Text:L 8:34 S BOYNAMES.TXT.jpg Search OT5GUC 57% content://media/external/fil 5 Jacob Michael Joshua Matthew Daniel Christopher Andrew Ethan Joseph William Anthony David Alexander Nicholas Ryan Tyler James John Jonathan Noah Brandon Christian Dylan Samuel Benjamin Zachary Nathan Logan Justin Gabriel Jose Austin Kevin Elijah Caleb Robert Thomas Jordan Cameron Jack Hunter Jackson Angel Isaiah Evan Isaac Mason Luke Jason Gavin Jayden Aaron Connor Aiden Aidan Kyle Juan Charles Luis Adam Lucas Brian Eric Adrian Nathaniel Sean Alex Carlos Bryan Ian Owen Jesus Landon Julian Chase Cole Diego Jeremiah Steven Sebastian Xavier Timothy Carter Wyatt Brayden Blake Hayden Devin Cody Richard Seth Dominic Jaden Antonio Miguel Liam Patrick Carson Jesse Tristan Alejandro Henry Victor Trevor Bryce Jake Riley Colin Jared Jeremy Mark Caden Garrett Parker Marcus Vincent Kaleb Kaden Brady Colton Kenneth Joel Oscar Josiah Jorge Cooper Ashton Tanner Eduardo Paul Edward Ivan Preston Maxwell Alan Levi Stephen Grant Nicolas Omar Dakota Alexis George Collin Eli Spencer Gage Max Cristian Ricardo Derek Micah Brody Francisco Nolan Ayden Dalton Shane Peter Damian Jeffrey Brendan Travis Fernando Peyton Conner Andres Javier Giovanni Shawn Braden Cesar Bradley Emmanuel Manuel Edgar Erik Mario Edwin Johnathan Devon Erick Wesley Oliver Trenton Hector Malachi Jalen Raymond Gregory Abraham Elias Leonardo Sergio Donovan Colby Marco Bryson Martin O GIRLNAMES.TXT.jpg Search 12:39 1 OT lll 50% Emily Madison Emma Olivia Hannah Abigail Isabella Samantha Elizabeth Ashley Alexis Sarah Sophia Alyssa Grace Ava Taylor Brianna Lauren Chloe Natalie Kayla Jessica Anna Victoria Mia Hailey Sydney Jasmine Julia Morgan Destiny Rachel Ella Kaitlyn Megan Katherine Savannah Jennifer Alexandra Allison Haley Maria Kaylee Lily Makayla Brooke Mackenzie Nicole Addison Stephanie Lillian Andrea Zoe Faith Kimberly Madeline Alexa Katelyn Gabriella Gabrielle Trinity Amanda Kylie Mary Paige Riley Jenna Leah Sara Rebecca Michelle Sofia Vanessa Jordan Angelina Caroline Avery Audrey Evelyn Maya Claire Autumn Jocelyn Ariana Nevaeh Arianna Jada Bailey Brooklyn Aaliyah Amber Isabel Danielle Mariah Melanie Sierra Erin Molly Amelia Isabelle Madelyn Melissa Jacqueline Marissa Shelby Angela Leslie Katie Jade Catherine Diana Aubrey Mya Amy Briana Sophie Gabriela Breanna Gianna Kennedy Gracie Peyton Adriana Christina Courtney Daniela Kathryn Lydia Valeria Layla Alexandria Natalia Angel Laura Charlotte Margaret Cheyenne Mikayla Miranda Naomi Kelsey Payton Ana Alicia Jillian Daisy Mckenzie Ashlyn Caitlin Sabrina Summer Ruby Rylee Valerie Skylar Lindsey Kelly Genesis Zoey Eva Sadie Alexia Cassidy Kylee Kendall Jordyn Kate Jayla Karen Tiffany Cassandra Juliana Reagan Caitlyn Giselle Serenity Alondra Lucy Kiara Bianca Crystal Erica Angelica Hope Chelsea Alana Liliana Brittany Camila Makenzie Veronica Lilly Abby Jazmin Adrianna Karina Delaney Ellie Jasmin
Test Case 1 Failed
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
Show what's missing
The name 'Xavier' was not found in either list.
type QUIT to exit: \n
Enter a name to search or
AMANDA ENTER
The name 'Amanda' was not
found in either list.\n
Enter a name to search or type QUIT to exit: \n
jordan ENTER
The name 'Jordan' was not found in either list.\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 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 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 Show what's missing The name 'Xavier' was not found in either list. type QUIT to exit: \n Enter a name to search or AMANDA ENTER The name 'Amanda' was not found in either list.\n Enter a name to search or type QUIT to exit: \n jordan ENTER The name 'Jordan' was not found in either list.\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 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
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education