JAVA
PLEASE REMOVE BOYNAMES.TXT IS MISSING AND Exiting program. Goodbye FROM THE PROGRAM. PLEASE MODIFY THIS PROGRAM WHICH IS LISTED BELOW BECAUSE WHEN I UPLOAD IT TO HYPEREGRADE IT DOES NOT PASS THE TEST CASE. IT SAYS 0 OUT OF 1 PASSED. I ONLY NEED IT TO READ BOYNAMES.TXT AND GIRLNAMES.TXT AND DISPLAY THE TEST CASE. ALSO, THE PROGRAM MUST DISPLAY THE FOLLOWING OUTPUT FOR TEST CASE WHICH ARE LISTED BELOW:
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
I HAVE PROVIDED THE FAILED TEST CASES AS A SCREENSHOT AND THE INPUTS FOR THE PROGRAM. THANK YOU.
import java.io.*;
import java.util.*;
public class NameSearcher {
private static List<String> loadFileToList(String filename) throws FileNotFoundException {
List<String> namesList = new ArrayList<>();
File file = new File(filename);
if (!file.exists()) {
throw new FileNotFoundException(filename);
}
try (Scanner scanner = new Scanner(file)) {
while (scanner.hasNextLine()) {
namesList.add(scanner.nextLine().trim().toLowerCase());
}
}
return namesList;
}
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;
try {
boyNames = loadFileToList("Boynames.txt");
girlNames = loadFileToList("Girlnames.txt");
} catch (FileNotFoundException e) {
System.out.println(e.getMessage() + " is missing.");
return;
}
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Enter a name to search or type QUIT to exit: ");
String input = scanner.nextLine().trim();
if (input.equalsIgnoreCase("QUIT")) {
break;
}
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) {
System.out.println("The name '" + capitalizedInput + "' was not found in either list.");
} else if (boyIndex != null && girlIndex == null) {
System.out.println("The name '" + capitalizedInput + "' was found in popular boy names list (line " + boyIndex + ").");
} else if (boyIndex == null && girlIndex != null) {
System.out.println("The name '" + capitalizedInput + "' was found in popular girl names list (line " + girlIndex + ").");
} else {
System.out.println("The name '" + capitalizedInput + "' was found in both lists: boy names (line " + boyIndex + ") and girl names (line " + girlIndex + ").");
}
}
scanner.close();
}
}
Step by stepSolved in 4 steps with 3 images
- Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (and hopefully funny) ways. Complete the program to read the needed values from input, that the existing output statement(s) can use to output a short story. Ex: If the input is: Eric Chipotle 12 cars the output is: Eric went to Chipotle to buy 12 different types of cars. 367012.2549490.qx3zqy7 LAB 2.14.1: LAB: Mad Lib 0/10 ACTIVITY LabProgram.java Load default template... 1 import java.util.Scanner; 2 3 public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String firstName; String genericLocation; int wholeNumber; String pluralNoun; 4 6 7 8 9 10 11 /* Type your code here. */ 12 System.out.println(firstName + } 13 went to + genericlocation + to buy + wholeNumber + differei 14 15arrow_forwardJava Program ASAP Modify this program so it passes the test cases in Hypergrade becauses it says 5 out of 7 passed. And do the following; 1) For test cases 2 and 3 for the outputted numbers there needs to be commas and there needs to be nothing after that 2)for test case 1 outputted numbers there needs to be nothing after that, 3) for test 4 when file is not found there needs to be nothing after that 4) and for test case 5 and 7 afer a file is not found it needs to display Please re-enter the file name or type QUIT to exit: so you input the text file and displays the numbers. import java.io.*;import java.util.Scanner;public class FileSorting { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); System.out.println("Please enter the file name or type QUIT to exit:"); while (true) { String input = sc.next(); if (input.equalsIgnoreCase("QUIT")) { break; // Exit the program…arrow_forwardX609: Magic Date A magic date is one when written in the following format, the month times the date equals the year e.g. 6/10/60. Write code that figures out if a user entered date is a magic date. The dates must be between 1 - 31, inclusive and the months between 1 - 12, inclusive. Let the user know whether they entered a magic date. If the input parameters are not valid, return false. Examples: magicDate(6, 10, 60) -> true magicDate(50, 12, 600) –> falsearrow_forward
- JAVA PROGRAM IN THE PROGRAM I DO NOT NEED BOYNAMES.TXT IS MISSING. ALSO, I DO NOT NEED Exiting program. Goodbye IN THE PROGRAM.I ONLY NEED IT TO READ BOYNAMES.TXT AND GIRLNAMES.TXT AND DISPLAY THE TEST CASE. ALSO, THE PROGRAM MUST DISPLAY THE FOLLOWING OUTPUT FOR TEST CASE WHICH ARE LISTED BELOW: Enter a name to search or type QUIT to exit:\nAnnabelleENTERThe name 'Annabelle' was not found in either list.\nEnter a name to search or type QUIT to exit:\nxavierENTER PLEASE MAKE THIS PROGRAM WORKS SO WHEN I UPLOAD IT TO HYPERGRADE IT PASSES ALL THE TEST CASES. I HAVE PROVIDED THE FAILED TEST CASES AS A SCREENSHOT AND THE INPUTS FOR THE PROGRAM. THANK YOU. Homework #2. Chapter 7. PC #13. Name Search (page 492) Read these instructions for additional requirements carefully. Write a program that reads the contents of the two files into two separate arrays. The user should be able to enter a name the application will display messages indicating whether the names were among the most popular.…arrow_forwardJava Program ASAP ************This program must work in hypergrade and pass all the test cases.********** I have provided the code instructions below. Please fix the program below with the following modifications: in Stop and smell the roses.\n the s needs to be Capital, a smaller case, s maller case r smaller case in the sentence. The same applies to A true rebel you are! Everyone was impressed. You'll do well to continue in the same spirit.\n Please explain a bit more in the way of footnotes. From the given text it's not clear what are we reading about.\n and Please explain a bit more in the way of footnotes. From the given text it's not clear what are we reading about.\n needs to be in another line. import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.regex.Pattern;import java.util.regex.Matcher;public class WordSeparator { public static void main(String[] args) { try…arrow_forwardHi, I need help with this coding problem on eclipse.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education