JAVA PROGRAM   Modify this program with further modifications as follows: The test case must pass when uploaded to Hypergrade.  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;     } }     Also, change the following from the program:  System.out.print("Enter a name (or 'QUIT' to exit): "); to this: Enter a name to search or type QUIT to exit and remove this from the program:  System.out.println(filename + " is missing. Exiting...");   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

icon
Related questions
Question
JAVA PROGRAM
 
Modify this program with further modifications as follows: The test case must pass when uploaded to Hypergrade. 

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;
    }
}

 
 
Also, change the following from the program: 

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

 

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

 

BOYNAMES.TXT
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 lan 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
GirlNames.txt
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:BOYNAMES.TXT 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 lan 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 GirlNames.txt 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 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
jOrd An 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 jOrd An 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 2 images

Blurred answer