Sample output from professor:
My code so far:
import java.util.*;
import java.io.*;
import java.text. DecimalFormat;
public class HW10 {
public static void main(String[] args) throws IOException {
System.out.println("Which file would you like to read?");
Scanner keyboard = new Scanner(System.in);
String name = keyboard.next();
Scanner reader = new Scanner(new File(name));
double numbers[][] = new double[reader.nextInt()+1][reader.nextInt()+1]; //+1 for averages
//loop over all the rows
for (int i=0; i<numbers.length; i++) {
//loop over all the columns in row i
for (int j=0; j<numbers[i].length; j++) {
//this code will execute on each and every cell row i, column j
numbers[i][j] = reader.nextDouble();
}
double sum = 0;
double average = (sum/(numbers.length));
}
//loop over all the rows
for (int i = 0; i<numbers.length-1; i++) {
System.out.println("Assignment #: ");
System.out.println("array 1, 2, 3, 4, 5, 6, Avg");
System.out.println("Student 1: ");
System.out.println("Student 2: ");
System.out.println("Student 3: ");
System.out.println("Student 4: ");
System.out.println("Student 5: ");
System.out.println("Average: ");
for (int j=0; j<numbers[i].length-1; j++) { //loop over all the columns in row i
System.out.print(numbers[i][j] + " "); //print out the cell value and then a space
}
//System.out.println("The overall class average is " + (totalResults/(numbers.length))); //the class average
DecimalFormat numPattern = new DecimalFormat("##.#");
}
//overall average code here
}
}
In order to display all of the content properly, the arrays need to be displayed such that the headings and print lines all make sense. I've done this by putting some placeholders into where I'm not understanding how to display the data.
Though the above code compiles, it gives me an exception error when the scores.txt file is inputted for the name -- the working directory contains the file, so I'm not sure why it's not moving past that in the program, either.
I think I'll be able to display the array just fine if I can get past that hurdle, but I seek the Stack's advice about how my code looks syntactically. Any insight for improvement?