Help with an Array Assignment
- From: "sanchezj" <u16152@uwe>
- Date: Mon, 28 Nov 2005 00:29:45 GMT
I need help with this assignment. Am I on track? Here is the code that I
have so far.
A school is giving a standardized test to all of its students. There are 50
questions on the test and the school would like to gather some statistics on
how the students performed. Scores can range anywhere from 0 to 50. All the
scores are stored in a file (scores.txt) that you can download. Read the data
from the file and calculate and output the following statistics: average
score, the mode of the scores, the highest/lowest score. In addition, output
a list of the scores and the number of students that received each score.
import java.io.*;
import java util.*;
public static void main (String [ ] args) throws FileNotFoundException
{
int [ ] scores = new int [50];
Scanner inFile = new Scanner(new FileReader (f:\\scores.txt));;
readData(inFile, scores);
print(scores);
System.out.println();
}
public static void readData(Scanner inputFile, int[] list)
{
int score;
int index;
while (inputFile.hasNext())
{
score = inputFile.nextInt();
index = score / ???;
if (index == list.length)
index--;
if (index < list.length)
list[index]++;
}
}
public static void print(int[] list)
{
int range;
int lowRange = 0;
int upperRange = 50;
System.out.println(" Range # of Students");
for (range = 0; range < list.length; range++)
{
System.out.printf("%4d - %3d %10d%n", lowRange,
upperRange, list[range]);
lowRange = upperRange + 1;
upperRange = upperRange + 25;
if (range == list.length - 2)
upperRange++;
}
System.out.println();
}
}
.
- Follow-Ups:
- Re: Help with an Array Assignment
- From: anon
- Re: Help with an Array Assignment
- From: Rhino
- Re: Help with an Array Assignment
- Prev by Date: Re: Junit newbie
- Next by Date: Re: read keyboard input and storing in an array?
- Previous by thread: cant's compile with javac
- Next by thread: Re: Help with an Array Assignment
- Index(es):
Relevant Pages
|
|