import java.io.*; public class HealthApp{ public static void main(String []args) throws IOException{ //Define the array to store Student objects Student[] patients = new Student[50]; //Define the variable to read from file BufferedReader inFile = new BufferedReader(new FileReader("student.txt")); //Define the variable to store name String tempName; //Define the variable to store age int tempAge; //Define the variable to store gender char tempGender; //Define the variable to store the actual number of student records int count; count = 0; while ((tempName = inFile.readLine())!=null){ tempAge = Integer.parseInt(inFile.readLine()); tempGender = inFile.readLine().charAt(0); patients[count] = new Student(tempName, tempAge, tempGender); count++; } System.out.println("The average student age is: " + Math.round(AverageAge(patients, count))); System.out.println("The oldest student is : " + OldestStudent(patients, count)); System.out.println("The total number of males in the group is : " + NumMales(patients, count)); inFile.close(); } public static double AverageAge(Student[] x, int actualNumOfStudents){ //Define the variable to store the average age double avAge; //Define the variable to store the sum age int tempSum; tempSum = 0; //Use for loop to calculate the sum age for(int i = 0; i < actualNumOfStudents; i++) tempSum += x[i].getAge(); //Calculate the average age avAge = (double)tempSum/(double)actualNumOfStudents; return avAge; } public static String OldestStudent(Student[] x, int actualNumOfStudents){ //Define the variable to store the name who has the oldest age String oldest = ""; //Define the variable to store the oldest age int oldestAge = 0; for(int i = 0; i < actualNumOfStudents; i++) { if(x[i].getAge() > oldestAge){ oldestAge = x[i].getAge(); oldest = x[i].getName(); } } return oldest + ", age " + oldestAge; } public static int NumMales(Student[] x, int actualNumOfStudents){ //Define the variable to store the number of males int maleSum=0; for(int i=0; i < actualNumOfStudents; i++){ if(x[i].getGender() == 'M'){ maleSum++; } } return maleSum; } }