Question

*12.1 (Name for both genders) Write a program that prompts the user to enter one of...

*12.1 (Name for both genders) Write a program that prompts the user to enter one of the filenames described in Exercise 12.31 and displays the names that are used for both genders in the file. Here is a sample run:

Enter a file name for baby name ranking: Babynamesranking2001.txt
69 names used for both genders
They are Tyler Ryan Christian ...

The original question had me enter a URL and file to access all the data, but the website no longer contains the files we are told to use.
I am not sure how to show the files in this post, but they are listed as:
babynamesranking2001.txt
babynamesranking2002.txt
babynamesranking2003.txt
babynamesranking2004.txt

I guess if someone could just show me how to access and print the required data values from a file as described above then I could figure it out for these files.

This is originally a C++ programming question, but we are doing it in Java. I was hoping someone would know how to do it.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go this code and let me know if u need any changes in this.Thank You
_________________

babynamesranking2001.txt

1 Michael 65,275 Jessica 46,470
2 Christopher 52,331 Ashley 45,553
3 Matthew 44,794 Brittany 36,534
4 Joshua 43,216 Amanda 34,405
5 Daniel 33,809 Samantha 25,865
6 David 33,739 Sarah 25,810
7 Andrew 33,653 Stephanie 24,859
8 James 32,344 Jennifer 22,219
9 Justin 30,635 Elizabeth 20,742
10 Joseph 30,124 Lauren 20,499
11 Ryan 29,242 Megan 20,256
12 John 29,066 Emily 19,361
13 Robert 28,865 Nicole 17,950
14 Nicholas 27,899 Kayla 17,536
15 Anthony 25,074 Amber 15,862
16 William 24,887 Rachel 15,704
17 Jonathan 24,064 Courtney 15,378
18 Kyle 22,698 Danielle 14,330
19 Brandon 22,155 Heather 14,217
20 Jacob 22,005 Melissa 13,997
21 Tyler 20,631 Rebecca 13,670
22 Zachary 20,424 Michelle 13,418
23 Kevin 20,403 Tiffany 13,157
24 Eric 19,412 Chelsea 12,782
25 Steven 18,753 Christina 11,925
26 Thomas 18,214 Katherine 11,618
27 Brian 16,919 Alyssa 11,262
28 Alexander 16,183 Jasmine 11,033
29 Jordan 16,131 Laura 10,908
30 Timothy 15,685 Hannah 10,274
31 Cody 15,392 Kimberly 10,193
32 Adam 14,708 Kelsey 9,494
33 Benjamin 14,619 Victoria 9,104
34 Aaron 14,550 Sara 8,973
35 Richard 13,574 Mary 8,665
36 Patrick 12,373 Erica 8,604
37 Sean 12,014 Alexandra 8,507
38 Charles 11,991 Amy 8,457
39 Stephen 11,940 Crystal 8,218
40 Jeremy 11,685 Andrea 8,211
41 Jose 11,508 Kelly 8,134
42 Travis 11,454 Kristen 8,073
43 Jeffrey 10,979 Erin 7,987
44 Nathan 10,934 Brittney 7,427
45 Samuel 10,883 Anna 7,290
46 Jason 10,680 Taylor 7,255
47 Mark 10,680 Maria 7,181
48 Jesse 8,980 Allison 7,131
49 Paul 8,579 Cassandra 7,052
50 Dustin 8,455 Caitlin 7,026
51 Gregory 8,377 Lindsey 6,781
52 Kenneth 8,258 Angela 6,664
53 Scott 8,083 Katie 6,513
54 Derek 8,075 Alicia 6,510
55 Austin 7,909 Jamie 6,509
56 Corey 7,690 Vanessa 6,405
57 Bryan 7,436 Kathryn 6,350
58 Ethan 6,988 Morgan 6,047
59 Alex 6,941 Jordan 5,955
60 Christian 6,776 Whitney 5,904
61 Juan 6,737 Brianna 5,678
62 Cameron 6,663 Christine 5,676
63 Jared 6,639 Natalie 5,633
64 Taylor 6,574 Lisa 5,344
65 Bradley 6,431 Kristin 5,300
66 Luis 5,788 Alexis 5,256
67 Cory 5,763 Jacqueline 5,237
68 Edward 5,741 Shannon 5,185
69 Shawn 5,719 Lindsay 5,037
70 Ian 5,460 Brooke 4,988
71 Evan 5,307 Catherine 4,893
72 Marcus 5,296 Olivia 4,623
73 Shane 5,273 April 4,570
74 Peter 5,215 Erika 4,566
75 Carlos 5,207 Katelyn 4,486
76 Trevor 5,140 Monica 4,452
77 Antonio 4,864 Kristina 4,389
78 Vincent 4,798 Kaitlyn 4,313
79 George 4,564 Paige 4,112
80 Keith 4,481 Molly 3,964
81 Phillip 4,453 Jenna 3,957
82 Victor 4,441 Leah 3,924
83 Dylan 4,414 Julia 3,909
84 Brett 4,392 Bianca 3,827
85 Chad 4,349 Tara 3,821
86 Nathaniel 4,342 Melanie 3,812
87 Donald 4,177 Marissa 3,806
88 Caleb 4,153 Cynthia 3,794
89 Casey 4,130 Holly 3,771
90 Jesus 4,127 Abigail 3,718
91 Blake 4,101 Meghan 3,692
92 Raymond 4,061 Kathleen 3,669
93 Mitchell 4,019 Julie 3,655
94 Adrian 3,999 Ariel 3,605
95 Joel 3,998 Alexandria 3,594
96 Erik 3,950 Veronica 3,587
97 Ronald 3,900 Patricia 3,578
98 Devin 3,862 Diana 3,544
99 Garrett 3,756 Gabrielle 3,541
100 Gabriel 3,694 Shelby 3,517

_____________________

// CountDisplayBabyNames.java

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class CountDisplayBabyNames {

   public static void main(String[] args) {
       //Creating an ArrayList which holds String
       ArrayList<String> arl=new ArrayList<String>();
      
       //Declaring variables   
       String line;
       int cnt=0;
       Scanner sc=null;
try {
   //Opening the input file
       sc=new Scanner(new File("babynamesranking2001.txt"));
      
       //Reading the data from the file
           while(sc.hasNext())
           {
               line=sc.nextLine();
               String arr[]=line.split(" ");
               for(int i=0;i<arr.length;i++)
               {
                   if(Character.toUpperCase(arr[i].charAt(0))>='A' && Character.toUpperCase(arr[i].charAt(0))<='Z')
                   {
                       //counting no of names in the file
                       cnt++;
                       //populate the names in the ArrayList
                       arl.add(arr[i]);
                   }
               }
           }
           sc.close();
           //Displaying the output
           System.out.println(cnt+" names used for both genders");
           System.out.println("They are :");
           for(int i=0;i<arl.size();i++)
           {
               System.out.print(arl.get(i));
               if(i<arl.size()-1)
               {
                   System.out.print(",");
               }
               if((i+1)%10==0)
                   System.out.println();
           }
       } catch (FileNotFoundException e) {
           System.out.println(e);
       }
  

  

   }

}

___________________________

Output:

200 names used for both genders
They are :
Michael,Jessica,Christopher,Ashley,Matthew,Brittany,Joshua,Amanda,Daniel,Samantha,
David,Sarah,Andrew,Stephanie,James,Jennifer,Justin,Elizabeth,Joseph,Lauren,
Ryan,Megan,John,Emily,Robert,Nicole,Nicholas,Kayla,Anthony,Amber,
William,Rachel,Jonathan,Courtney,Kyle,Danielle,Brandon,Heather,Jacob,Melissa,
Tyler,Rebecca,Zachary,Michelle,Kevin,Tiffany,Eric,Chelsea,Steven,Christina,
Thomas,Katherine,Brian,Alyssa,Alexander,Jasmine,Jordan,Laura,Timothy,Hannah,
Cody,Kimberly,Adam,Kelsey,Benjamin,Victoria,Aaron,Sara,Richard,Mary,
Patrick,Erica,Sean,Alexandra,Charles,Amy,Stephen,Crystal,Jeremy,Andrea,
Jose,Kelly,Travis,Kristen,Jeffrey,Erin,Nathan,Brittney,Samuel,Anna,
Jason,Taylor,Mark,Maria,Jesse,Allison,Paul,Cassandra,Dustin,Caitlin,
Gregory,Lindsey,Kenneth,Angela,Scott,Katie,Derek,Alicia,Austin,Jamie,
Corey,Vanessa,Bryan,Kathryn,Ethan,Morgan,Alex,Jordan,Christian,Whitney,
Juan,Brianna,Cameron,Christine,Jared,Natalie,Taylor,Lisa,Bradley,Kristin,
Luis,Alexis,Cory,Jacqueline,Edward,Shannon,Shawn,Lindsay,Ian,Brooke,
Evan,Catherine,Marcus,Olivia,Shane,April,Peter,Erika,Carlos,Katelyn,
Trevor,Monica,Antonio,Kristina,Vincent,Kaitlyn,George,Paige,Keith,Molly,
Phillip,Jenna,Victor,Leah,Dylan,Julia,Brett,Bianca,Chad,Tara,
Nathaniel,Melanie,Donald,Marissa,Caleb,Cynthia,Casey,Holly,Jesus,Abigail,
Blake,Meghan,Raymond,Kathleen,Mitchell,Julie,Adrian,Ariel,Joel,Alexandria,
Erik,Veronica,Ronald,Patricia,Devin,Diana,Garrett,Gabrielle,Gabriel,Shelby

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
*12.1 (Name for both genders) Write a program that prompts the user to enter one of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a python program that prompts the user for the names of two text files and...

    Write a python program that prompts the user for the names of two text files and compare the contents of the two files to see if they are the same. If they are, the scripts should simply output “Yes”. If they are not, the program should output “No”, followed by the first lines of each file that differ from each other. The input loop should read and compare lines from each file. The loop should break as soon as a...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • JAVA Write a program that prompts the user to enter a file name, then opens the...

    JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...

  • ****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of...

    ****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of a file. The program encoded sentences in the file and writes the encoded sentences to the output file. Enter the file name: messages.txt Output: encoded words are written to file: messages.txt.swt The program reads the content of the file and encodes a sentence by switching every alphabetical letter (lower case or upper case) with alphabetical position i, with the letter with alphabetical position 25...

  • C++ (1) Write a program to prompt the user for an input and output file name....

    C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...

  • Help me write a python code. Write a program that asks the user for the name...

    Help me write a python code. Write a program that asks the user for the name of a text file, then reads each line of the text file and prints it on the screen, making every other line "title case." For example, suppose the following text is saved in my_file.txt: While I nodded, nearly napping Suddenly there came a tapping As of someone gently rapping, Rapping at my chamber door. When run, the program looks like this: Enter filename: While...

  • Develop a functional flowchart and then write a C++ program to solve the following problem. 1....

    Develop a functional flowchart and then write a C++ program to solve the following problem. 1. Create a text file named c1.txt and write your brand of computer (like Dell, HP, etc) in the file. You will be reading the name of the file from the keyboard as a string, using the string class. Your program will also read the brand of your computer from the keyboard. The process of the file creation (name of the file, mode for opening...

  • Python Help Please! This is a problem that I have been stuck on.I am only suppose...

    Python Help Please! This is a problem that I have been stuck on.I am only suppose to use the basic python coding principles, including for loops, if statements, elif statements, lists, counters, functions, nested statements, .read, .write, while, local variables or global variables, etc. Thank you! I am using python 3.4.1. ***( The bottom photo is a continuation of the first one)**** Problem statement For this program, you are to design and implement text search engine, similar to the one...

  • Stuck on this computer science assignment Write a program that demonstrates binary searching through an array...

    Stuck on this computer science assignment Write a program that demonstrates binary searching through an array of strings and finding specific values in an corresponding parallel double array. In all cases your output should exactly match the provided solution.o. Provided files: Assignment.cpp - starter assignment with function prototypes companies.txt - file for program to read. earnings.txt - file for program to read. Input1.txt Input2.txt - Test these inputs out manually, or use stream redirection Input3.txt - These inputs are based...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT