CSV generation changes
This commit is contained in:
parent
875b39ac61
commit
f367068e74
@ -1,74 +0,0 @@
|
|||||||
package csv;
|
|
||||||
|
|
||||||
public class CSV {
|
|
||||||
|
|
||||||
private String studentNumber; // we put here the idendificator number for each students
|
|
||||||
private double grade; // we put here the grade of each copies.
|
|
||||||
|
|
||||||
public CSV() {
|
|
||||||
this.studentNumber = null;
|
|
||||||
this.grade = .0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CSV(String s, double d) {
|
|
||||||
if (checkStudentNumber(s)) {
|
|
||||||
this.studentNumber = s;
|
|
||||||
this.grade = d;
|
|
||||||
} else {
|
|
||||||
System.err.println(
|
|
||||||
"The student number is not correct, please enter a valid number (from 1 to 16 characters)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CSV(String s, String d) {
|
|
||||||
if (checkStudentNumber(s)) {
|
|
||||||
this.studentNumber = s;
|
|
||||||
this.grade = Double.parseDouble(d);
|
|
||||||
} else {
|
|
||||||
System.err.println(
|
|
||||||
"The student number is not correct, please enter a valid number (from 1 to 16 characters)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean checkStudentNumber(String s) {
|
|
||||||
int i = 0;
|
|
||||||
boolean retour = false;
|
|
||||||
if (s.length() >= 1 && s.length() <= 16) {
|
|
||||||
while (i < s.length())
|
|
||||||
{
|
|
||||||
if (s.charAt(i) == '0' || s.charAt(i) == '1' || s.charAt(i) == '2' || s.charAt(i) == '3'
|
|
||||||
|| s.charAt(i) == '4' || s.charAt(i) == '5' || s.charAt(i) == '6' || s.charAt(i) == '7'
|
|
||||||
|| s.charAt(i) == '8' || s.charAt(i) == '9')
|
|
||||||
{
|
|
||||||
retour = true;
|
|
||||||
} else {
|
|
||||||
retour = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return retour;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "The student " + getStudentNumber() + " gets a " + getGrade() + " grade !";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStudentNumber() {
|
|
||||||
return studentNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStudentNumber(String s) {
|
|
||||||
this.studentNumber = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getGrade() {
|
|
||||||
return grade;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGrade(double d) {
|
|
||||||
this.grade = d;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
package csv;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
|
|
||||||
public class Generate {
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
|
|
||||||
for (int i = 0; i < csvList.size(); i++) {
|
|
||||||
|
|
||||||
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"));
|
|
||||||
|
|
||||||
}
|
|
||||||
System.out.println("Create File Done!");
|
|
||||||
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
System.err.println(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -11,33 +11,37 @@ public class GenerateCSV {
|
|||||||
int numLength;
|
int numLength;
|
||||||
String path = "../export";
|
String path = "../export";
|
||||||
|
|
||||||
public GenerateCSV(HashMap<String,String> map, String s, String p) {
|
public GenerateCSV(HashMap<String,String> map, String length, String pth) {
|
||||||
this.etudiants = map;
|
this.etudiants = map;
|
||||||
this.numLength = Integer.parseInt(s);
|
this.numLength = Integer.parseInt(length);
|
||||||
this.path = path+"/"+p;
|
this.path = path+"/"+pth;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public boolean isValid(String s) {
|
|
||||||
// int i = 0;
|
// TO DO : exploiter dans generation
|
||||||
// if (s.length() == this.numLength) {
|
public boolean isValid(String s) {
|
||||||
// while (i < s.length())
|
int i = 0;
|
||||||
// {
|
if (s.length() == this.numLength) {
|
||||||
// if (s.charAt(i) != '0' && s.charAt(i) == '1' || s.charAt(i) == '2' || s.charAt(i) == '3'
|
while (i < s.length()) {
|
||||||
// || s.charAt(i) == '4' || s.charAt(i) == '5' || s.charAt(i) == '6' || s.charAt(i) == '7'
|
|
||||||
// || s.charAt(i) == '8' || s.charAt(i) == '9')
|
int nb = Character.getNumericValue(s.charAt(i));
|
||||||
// {
|
|
||||||
// return true;
|
if (nb <= 0 || nb >= 9) {
|
||||||
//
|
System.err.println("Student id's characters are not recognized");
|
||||||
// } else {
|
return false;
|
||||||
// return false;
|
}
|
||||||
// break;
|
else {
|
||||||
// }
|
i++;
|
||||||
// i++;
|
}
|
||||||
// }
|
|
||||||
// }
|
}
|
||||||
//
|
return true;
|
||||||
// return true;
|
}
|
||||||
// }
|
else {
|
||||||
|
System.err.println("Student id's length is not correct");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,41 +7,41 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
public class TestCSV {
|
public class TestCSV {
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void createNullCSV() {
|
// public void createNullCSV() {
|
||||||
//We check if a CSV object cannot be created !
|
// //We check if a CSV object cannot be created !
|
||||||
CSV c = new CSV();
|
// CSV c = new CSV();
|
||||||
assertEquals(null, c.getStudentNumber());
|
// assertEquals(null, c.getStudentNumber());
|
||||||
assertEquals(.0, c.getGrade());
|
// assertEquals(.0, c.getGrade());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void checkFalseStudentnumber() {
|
// public void checkFalseStudentnumber() {
|
||||||
//We check if the student number is full composed of numeric digits !
|
// //We check if the student number is full composed of numeric digits !
|
||||||
String s = "056498a198";
|
// String s = "056498a198";
|
||||||
assertEquals(false, CSV.checkStudentNumber(s));
|
// assertEquals(false, CSV.checkStudentNumber(s));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void checkStudentNumberTooShort() {
|
// public void checkStudentNumberTooShort() {
|
||||||
//We check if the student number is enought long !
|
// //We check if the student number is enought long !
|
||||||
String s = "";
|
// String s = "";
|
||||||
assertEquals(false, CSV.checkStudentNumber(s));
|
// assertEquals(false, CSV.checkStudentNumber(s));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void checkStudentNumberTooLong() {
|
// public void checkStudentNumberTooLong() {
|
||||||
//We check if the student number is enought short !
|
// //We check if the student number is enought short !
|
||||||
String s = "012345678910111213141516";
|
// String s = "012345678910111213141516";
|
||||||
assertEquals(false, CSV.checkStudentNumber(s));
|
// assertEquals(false, CSV.checkStudentNumber(s));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void checkCorrectStudentNumber() {
|
// public void checkCorrectStudentNumber() {
|
||||||
//We check if the student number is correct !
|
// //We check if the student number is correct !
|
||||||
String s = "123456789";
|
// String s = "123456789";
|
||||||
assertEquals(true, CSV.checkStudentNumber(s));
|
// assertEquals(true, CSV.checkStudentNumber(s));
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user