M332-PT-NGCC/NGCC/src/csv/Generate.java

79 lines
1.5 KiB
Java
Raw Normal View History

2019-09-19 14:57:06 +02:00
package csv;
2019-09-19 13:56:08 +02:00
2019-09-23 12:39:34 +02:00
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
2019-09-19 13:56:08 +02:00
public class Generate {
2019-09-23 12:39:34 +02:00
private static String path = "grades";
BufferedReader csvReader;
private static ArrayList<CSV> csvList = new ArrayList<CSV>();
public static void start() {
createFile();
}
public static void start(String p) {
createFile(p);
}
2019-09-19 13:56:08 +02:00
2019-09-23 12:39:34 +02:00
public static void addList(String n, String g) {
CSV o = new CSV(n, g);
csvList.add(o);
}
public static void createFile(String p) {
SetPath(p);
createFile();
}
public static void createFile() {
try (PrintWriter writer = new PrintWriter(new File(path + ".csv"))) {
StringBuilder sb = new StringBuilder();
sb.append("Student number");
sb.append(',');
sb.append("Grade");
sb.append('\n');
writer.write(sb.toString());
2019-09-24 08:08:46 +02:00
for (int i = 0; i < csvList.size(); i++) {
2019-09-23 12:39:34 +02:00
2019-09-24 08:08:46 +02:00
sb.delete(0, sb.length());
sb.append(csvList.get(i).getStudentNumber());
sb.append("; ");
sb.append(csvList.get(i).getGrade());
writer.write(sb + System.getProperty("line.separator"));
}
2019-09-23 12:39:34 +02:00
System.out.println("Create File Done!");
} catch (FileNotFoundException e) {
2019-09-24 08:08:46 +02:00
System.err.println(e.getMessage());
2019-09-23 12:39:34 +02:00
}
}
public String getPath() {
return Generate.path;
}
public static void SetPath(String s) {
path = s;
}
public ArrayList<CSV> getCsvList() {
return csvList;
}
public void setCsvList(ArrayList<CSV> csvList) {
Generate.csvList = csvList;
}
2019-09-19 13:56:08 +02:00
}