Assignment #6 Solution



This assignment focuses on reading input file and on using array structures. You will need, which you used on previous assignments, and to write this program. Be sure to include a short comment at the beginning of your program as well as a short comment for each method describing what it does. For this assignment you are limited to the language features in Chapters 17 shown in lecture or the textbook.

1. (10 points) 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 the same folder as your program. 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 in the data file. The file contains student name followed by 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. 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.dat

Which gender do you want? female



We have 2 female students. Average age is 19.5.

2. (30points). Rewrite your program which is assignment 5 so that your program includes array structure. You have to include five arrays to store x coordinate, y coordinate, speed, direction and color for each ball. If you havent finished the assignment 5 yet, download and use it. The file was created by one of the students in our class.