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 boy_names = new ArrayList();

ArrayList boy_names_percent = new ArrayList();

ArrayList girl_names = new ArrayList();

ArrayList girl_names_percent = new 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!