# A few questions about java

• Java
Gold Member
This seems strange. I just realized that I was being careful enough with my code (while typing out my logic on here) that I don't actually need the try catch block, assuming the file always comes in the correct format (which I will only ever have to read this one file). I got rid of the try catch to try to simplify the program a bit. I also deleted a lot of things to try to clean it up. I think this is peculiar, but hopefully someone can show my why it's not.
Java:
import java.io.*;
import java.util.*;

public class ProgressReport{

Student[][] student;  //An array of student objects, the one we care about
Student[][] add;  //A secondary array, used for adding length to the student array (in number of students
Student[][] col;  //A preemptive strike, presumably I will need a third array for columns, currently unused
int[] sec = {0,0}; //number of students per section
int[] scores = {0,0,0,0,0};  // Scores for a section
String name = "";  //Name of the student

public ProgressReport() throws FileNotFoundException{
student = new Student[1][1];  //initialization
generateReport();
}

@SuppressWarnings("resource")
Scanner s = new Scanner(file);  //used to get the next line from the file
Scanner line; //used to get the next token on a line

int[] moar; // used to add sections to sec
int k = 0; //index of student within a section
int j = -1; //index of sec that carries the number of students
String score;

while(s.hasNextLine())
{
String str = s.nextLine(); //get next line

if(str.length() <= 3)
{
j++; //move to the next section
k=0; //set student index to zero (first student in the class)
if(j>2)
{
moar = new int[sec.length+1];
for(int ii = 0;ii<sec.length+1;ii++){
moar[ii] = sec[ii]; // add length and copy array
}
sec = moar.clone();
}
sec[j] = Integer.parseInt(str);  // turn the string value of the number of students to an int
student[j] = new Student[sec[j]]; //create a column of length sec[j]
for(int jj = 0; jj<=j; jj++){
for(int kk = 0 ; kk<=k;kk++){
}
}
}

else{
line = new Scanner(str);
while(line.hasNext())
{
name = line.next();
for(int i =0; i<scores.length ;i++)
{
score = line.next(); //set name equal to the next token
scores[i] = Integer.parseInt(score); //check if name is an int
}
student[j][k] = new Student(name, scores);

System.out.println(student[j][k].getName());
System.out.println(student[j][k].getAverage());

System.out.println(j+","+k);
k++;
}
}
}

}

private void generateReport(){
System.out.println("Progress Report \n");
for(int i = 0 ;i<=sec.length;i++)
{
System.out.println("Section " +(i+1));
for(int j = 0; j<=sec[i];j++)
{
System.out.println(student[i][j].getName() + " " + student[i][j].getAverage() + " " + student[i][j].getGrade());
}
}
}
}

I get this output:
Code:
Johnson
90.6
A
0,0
Aniston
81.2
B
0,1
Cooper
82.2
B
0,2
Gupta
72.2
C
0,3
Blair
52.2
F
0,4
Clark
59.2
F
1,0
Kennedy
63.4
D
1,1
Bronson
90.0
A
1,2
Sunny
84.8
B
1,3
Smith
75.4
C
1,4
Diana
68.8
D
1,5
Progress Report

Section 1
Johnson 90.6 A
at ProgressReport.generateReport(ProgressReport.java:117)
at Lab1A.main(Lab1A.java:6)