Question: Write a Java program that outputs a list of students from the given data file. Download the data file (student.txt) from our web site to
Write a Java program that outputs a list of students from the given data file. Download the data file (student.txt) from our web site to your project folder. You have to input the name of the data file from keyboard. You have to use input.hasNext() or input.hasNextInt() or input.hasNextDouble()with while loop when your program reads tokens from the file. We are assuming that you dont know how many lines are in the data file. The file contains student id followed by name, gender and age. You also have to input (from keyboard) f or female if you want to print a list of female students, and m or male if you want print a list of male students. Your program outputs the students name and total number of students of the gender and their average age (data type: Double).
For example, if your data file contains the following data:
1 John m 18
2 William m 22
3 Susan f 21
4 Jack m 19
5 Jennifer f 18
Your program should produce the following output:
What is the file name? student.txt
Which gender do you want?
Female List of Female Student
==================
Name age Susan 21 Jennifer 18 We have 2 female students. Average age is 19.5.
Student.txt file information:
1. John m 18 2. William m 22 3. Susan f 21 4. Jack m 19 5. Jennifer f 18 6. Sophia f 21 7. Emma f 19 8. Olivia f 26 9. Ava f 23 10. Tom m 22 11. Mia f 18 12. Isabella f 29 13. Zoe f 17 14. Lily f 20
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
