Write a Java program that outputs a list of students from the given data file (h
ID: 3571712 • Letter: W
Question
Write a Java program that outputs a list of students from the given data file (home.txt). You have to input the name of the data file from keyboard. You have to use input.hasNext()with while loop when your program reads tokens from the file. We are assuming that you don’t know how many lines are in the data file. The file contains student name followed by their hometown. Your program should output each hometown, total number of students from each hometown, and each student’s name belonging in the hometown.
For example, if your data file contains the following data:
John Seattle
William Yakima
Susan Yakima
Jack Lapush
Jennifer Seattle
Kim Seattle
Your program should produce the following output (Bold is user input):
What is the file name? home.txt
Seattle students: 3
John
Jennifer
Kim
Yakima students: 2
William
Susan
Lapush students: 1
Jack
Explanation / Answer
Please find the required program along with its output. Please see the comments against each line to understand the step.
-----------------------------------------------------------------------------
OUTPUT:
home.txt
Seattle students: 3
John
Jennifer
Kim
Yakima students: 2
William
Susan
Lapush students: 1
Jack
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.