statistics

Download Statistics

If you can't read please download the document

Upload: kyle-chadee

Post on 27-Sep-2015

1 views

Category:

Documents


0 download

DESCRIPTION

Java code for statistics

TRANSCRIPT

/** * @(#)Statistics.java *@author * @version 1.00 2015/3/31 * * *KYLE CHADEE *813001933 * * */import java.io.*; //import java io and the util functionimport java.util.*;public class Statistics{public static void main(String [] args) throws IOException{// throws the io functionScanner in = new Scanner (new FileReader("students.dat")); //opens the file to read fromint count=0,Hspan=0,Hmath=0,Hfren=0,HEng=0,Spanish,French,English,math; double avg,highestAvg=0; String HName="z",name; //This id the declartions section where values were initalised name=in.next(); //Reads the first name from the file while(!name.equals("ENDDATA")){ //while loop is for iteration through the file and get values Spanish=in.nextInt(); math=in.nextInt();// reads in the values French=in.nextInt(); English=in.nextInt();avg=(Spanish+math+French+English)/4;if (avg>highestAvg){highestAvg=avg;HName=name;// calculates the average of the alll the course marks for the student}//end if statementcount=count+1;System.out.printf("\nFor the student named %s, and their average is: %3.2f\n",name,avg); //displays the data supplied by the average equation.if (Spanish>Hspan){ /// these "if loops" are there to determineHspan=Spanish;}if (math>Hmath){Hmath=math;} //the highest Spansih score"Hspan"if (French>Hfren){// Hfren is for the highest french scoreHfren=French;}// Hmath means Highest math scoreif (English>HEng){//HEng highest english scoreHEng=English;}name=in.next(); //reads in the next name of the person }//end while loop System.out.printf("\nThe highest student avg in class is: %3.2f\n",highestAvg); //prints out the student with higest averageSystem.out.printf("\nThe name of the student who attained the higest avg is: %s \n",HName); // prints out the student who made the highest averageSystem.out.printf("\nThe highest scores for each subject is:\nSpanish: %d\nEnglish: %d\nFrench: %d\nMath: %d \n\n",Hspan,HEng,Hfren,Hmath);// prints out the highest score for each subjectSystem.out.printf("The number of Students in the class is %d",count);// prints the number of students in the class using a count, to calculate it.in.close();} // end class} //end main