Question
Develop a program to read and process babynames.txt. When the program starts, it automatically read the text file in store the names and percentages in
Develop a program to read and process babynames.txt. When the program starts, it automatically read the text file in store the names and percentages in the array lists. The main program has user menu with the following four options. (W)rite text files for boy and girl name (P)rint all boy and girl names with percentage > N % (S)elect all girl names that include character X (Q)uit program The user can select the options by typing W, P, S, or Q in the main menu. When W is selected, two text files (boynames.txt and girlnames.txt) will be created. When P is selected, the user is asked to enter N (in percentages). Then, all boy and girl names with percentage > N % are printed. When S is selected, the user is asked to enter X (a single character). Then, all girl names that includes character X will be printed. When user selects Q, the program terminates. Check Appendix in Page 2 for a sample run of the program.
public class BabyName {
public static void main(String[] args) throws FileNotFoundException {
System.out.println("###################################################");
System.out.println("######## Baby Names Search Program ########");
System.out.println("###################################################");
Scanner console = new Scanner(System.in);
boolean continueProgram = true;
ArrayList
ArrayList
ArrayList
ArrayList
System.out.print("Reading data file \"babynames.txt\"... ");
// Insert code to read babynames.txt and store the names and percentages into the array lists.
System.out.println("data file loaded! ");
while(continueProgram) {
System.out.println("-------------------------------------------");
System.out.println("(W)rite text files for boy and girl name"); // Type "W" for write option
System.out.println("(P)rint all boy and girl names with percentage > N %");
System.out.println("(S)elect all girl names that include character X");
System.out.println("(Q)uit program"); // Type "Q" to quit the program
System.out.println("-------------------------------------------");
System.out.print("Select menu: ");
String option = console.next();
if(option.equals("W")) {
// Complete W option to write boynames.txt and girlnames.txt
System.out.println("[MSG] Output files written. ");
System.out.println();
System.out.println();
}else if(option.equals("P")) {
// Complete P option. You can assume that the user will provide a double number.
System.out.print("Enter N (in percentages): ");
double percentage = console.nextDouble();
System.out.println("[Message] Output names printed. ");
System.out.println();
System.out.println();
}else if(option.equals("S")){
// Complete S option. You can assume that the user will provide a single character.
System.out.println("[Message] Output names printed. ");
System.out.println();
System.out.println();
}else if(option.equals("Q")){
// Complete Q option.
System.out.println("[Message] Terminating program. ");
System.out.println();
System.out.println();
}
}
console.close();
}
}
*Please use java and also read from the babyname.txt file using a scanner*
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started