I tried to go with a simple fix to my issue for printing the array to the .csv file and replacing certain characters, however I noticed later that I am not supposed to use any spaces before or after the commas in my output.
I can't use replace or else all of the header labels will have zero spaces either, so I need help with getting the values directly from my nested for loops.
import java.io.*;
import java.util.Arrays;
public class HW01 {
public static void main(String args[]) throws IOException {
// Create a 1D array to hold header labels
String headerLabels[] =
{"COURSE ID", "TEAM ID", "STUDENT FIRST NAME",
"STUDENT LAST NAME", "STUDENT ID", "ASSIGNMENT ID",
"DATE SUBMITTED", "TIME SUBMITTED", "SUBMITTED BY"
};
// Create a 2D array to hold header values
String headerValues[][] =
{
{"CMPS280-02", "Invokers01", "James", "Brown", "w0479045", "H01", "8/25/2017", "1:14PM", "James Brown"},
{"CMPS280-01", "Winners03", "Jacob", "Harley", "w0389342", "H03", "8/23/2017", "7:24PM", "Jacob Harley"},
{"SE101-02", "CodeIt00", "Keith", "Dillinger", "w0782345", "S04", "8/25/2017", "1:23AM", "Keith Dillinger"}
};
// Create an int to hold number of students
int students = headerValues.length;
// Array loop to create student .csv files
for (int i = 0; i < headerValues.length; i++){
for (int j = 0; j < students; j++){
// Create new .csv file and store in SUBMIT folder
String path = "SUBMIT/"+headerValues[i][0]+"_"+headerValues[i][5]+"_"+headerValues[i][1]+"_"+headerValues[i][4]+".csv";
File file = new File(path);
PrintWriter writer = new PrintWriter(file);
// Print headerLabels and headerValues for each student into .csv files
writer.println(Arrays.toString(headerLabels).replace("[", "").replace("]", "").replace(" , " , ","));
writer.println(Arrays.toString(headerValues[i]).replace("[", "").replace("]", "").replace(" , ", ","));
writer.close();
}
}
}
}