You are going to work with baby name files again. Complete the GirlNamesWithZ ap
ID: 3843610 • Letter: Y
Question
You are going to work with baby name files again. Complete the GirlNamesWithZ application. Read the file and print a list of girl's names that contain the letter z or Z.
Do not change the declaration of the filename. Codecheck will run it twice. Once with each file name below.
Do not use try / catch here. Just declare that the method throws an exception.
Copy these file into your project:
----------------------------babynames2000s.txt---------------------------------------------
----------------------------------------------------------------------------------
------------------------------babynames1900s.txt------------------------------
------------------------------------------------------------------------
Complete the following file:
GirlNamesWithZ.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class GirlNamesWithZ
{
public static void main(String[] args) throws FileNotFoundException
{
String filename = "babynames2000s.txt";
}
}
Explanation / Answer
GirlNamesWithZ.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class GirlNamesWithZ
{
public static void main(String[] args) throws FileNotFoundException
{
String filename = "babynames2000s.txt";
Scanner scan = new Scanner(new File(filename));
scan.nextLine();
scan.nextLine();
while(scan.hasNextLine()) {
String line = scan.nextLine();
String words[] = line.split("\s+");
String girlName = words[3];
if(girlName.contains("z") || girlName.contains("Z")) {
System.out.println(girlName);
}
}
}
}
Output:
Elizabeth
Mackenzie
Zoe
Mckenzie
Zoey
Makenzie
Jazmin
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.