java - Calculating Avg, Max, and Min using a .txt input file with both integers and strings mixed -


please help. i've looked everywhere , stumped on how finish program. need calculate average, max, , min data input file. need this:

system.out.println("the average total score of class is: " + total/27); system.out.println(maxname + "got maximum score of: " + maxval); system.out.println(minname + "got maximum score of: " + minval); 

for average don't know why while loop in main isn't working. calculates value of zero. don't know how can make 27 isn't hard coded. max , min values, have no clue those. don't have guess. lot of things i've looked @ these use ways haven't been taught (like buffered instance, or using collections class haven't learned either. need basic way of accomplishing these. include have far. appreciated. thank you.

input file:

9 andy borders 200 250 400 john smith 120 220 330 alvin smith 225 300 278 mike borell 250 250 500 jim jones 325 325 155 robert fennel 200 150 350 craig fenner 230 220 480 bill johnson 120 150 220 brent garland 220 240 350 

main:

import java.util.scanner; import java.io.*; public class project5 {  public static void main(string[] args) {     scanner in = new scanner(system.in);     system.out.println("enter file name: ");     string filename = in.nextline();     try {         file file = new file(filename);         scanner inputfile = new scanner(file);         string snumstudents = inputfile.nextline();         int numstudents = integer.parseint(snumstudents);         student [] studentlist = new student[numstudents];         (int = 0; < numstudents; i++)         {             string line = inputfile.nextline();             string score1 = inputfile.nextline();             string score2 = inputfile.nextline();             string score3 = inputfile.nextline();             studentlist [i] = new student(line, integer.parseint(score1), integer.parseint(score2), integer.parseint(score3));         }         system.out.println("name\t\tscore1\tscore2\tscore3\ttotal");         system.out.println("---------------------------------------------");         (int i=0; i< studentlist.length;i++){             system.out.println(studentlist[i].getname() + "\t" + studentlist[i].getscore1() + "\t" + studentlist[i].getscore2() + "\t" + studentlist[i].getscore3() + "\t" + studentlist[i].gettotal());         }         system.out.println("---------------------------------------------");         system.out.println("the total number of students in class is: " + studentlist.length);         int total = 0;         while (inputfile.hasnextint())         {             int value = inputfile.nextint();             total = total + value;         }         system.out.println("the average total score of class is: " + total/27);         system.out.println(maxname + "got maximum score of: " + maxval);         system.out.println(minname + "got maximum score of: " + minval);         inputfile.close();     } catch (ioexception e) {         system.out.println("there problem reading " + filename);     }     {     }     in.close(); } } 

student class:

public class student { private string name; private int score1; private int score2; private int score3; private int total; private double average;  public student(string n, int s1, int s2, int s3){     name = n;     score1 = s1;     score2 = s2;     score3 = s3;     total = s1 + s2 + s3; } public string getname(){     return name; } public int getscore1(){     return score1; } public int getscore2(){     return score2; } public int getscore3(){     return score3; } public int gettotal(){     return total; } public double computeaverage(){     return average; } } 

your while loop never getting executed. time finish reading lines of file in loop, there no more lines of file consume. so, inputfile.hasnextint() never true.

the 27 hard-coded because of line

system.out.println("the average total score of class is: " + total/27); 

you need change 27 here variable represent total number of scores.

you storing of scores each person. find min (max) need go through each of values , find smallest (largest) 1 , store them.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -