Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; import java.util.*;

/** * Code for HW4 * This class process babynames.txt * */ 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 a scanner to read inputs*

Sample text file

1 Michael 462085 2.2506 Jessica 302962 1.5436 2 Christopher 361250 1.7595 Ashley 301702 1.5372 3 Matthew 351477 1.7119 Emily 237133 1.2082 4 Joshua 328955 1.6022 Sarah 224000 1.1413 5 Jacob 298016 1.4515 Samantha 223913 1.1408 6 Nicholas 275222 1.3405 Amanda 190901 0.9726 7 Andrew 272600 1.3277 Brittany 190779 0.9720 8 Daniel 271734 1.3235 Elizabeth 172383 0.8783 9 Tyler 262218 1.2771 Taylor 168977 0.8609 10 Joseph 260365 1.2681 Megan 160312 0.8168 11 Brandon 259299 1.2629 Hannah 158647 0.8083 12 David 253193 1.2332 Kayla 155844 0.7940 13 James 244775 1.1922 Lauren 153530 0.7822 14 Ryan 241105 1.1743 Stephanie 149725 0.7628

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions