Fakultas Ilmu Komputer UI

Commit e25589ee authored by Bagus Prabowo's avatar Bagus Prabowo
Browse files

CSV for Assignment List

parent 58edd09e
Pipeline #81850 failed with stages
in 40 seconds
admin,Admin
st,Student
ta,Teaching Assistant
\ No newline at end of file
ta,Teaching Assistant
......@@ -271,6 +271,8 @@ public class Student extends Role {
assignment.setCreatedBy(Main.currentUser);
assignmentList.addAssignment(assignmentName, assignment);
CSVAssignment.writeAssignment(assignment);
for (String s: coursesPicked) {
courseList.getCourseList().get(Integer.parseInt(s) - 1).addAssignment(assignment);
}
......@@ -288,14 +290,22 @@ public class Student extends Role {
case 14:
System.out.println("Pick the assignment that you want to validate:");
String[] assignmentsPicked = in.next().split("");
System.out.println("Picked: ");
for (String s: assignmentsPicked) {
System.out.println(s + " " + assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName());
String courseAssignment = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentCourse().getCourseName();
String assignmentName = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName();
validateAssignment(courseAssignment, assignmentName);
int cnt = 1;
for(Assignment s : assignmentList.getAssignmentList()){
System.out.println(cnt + ". " + s.getAssignmentName());
cnt++;
}
String assignmentPicked = in.next();
Assignment picked = assignmentList.getAssignmentList().get(Integer.parseInt(assignmentPicked) - 1);
System.out.println("Picked: " + picked.getAssignmentName());
String courseAssignment = picked.getAssignmentCourse().getCourseName();
String assignmentName = picked.getAssignmentName();
validateAssignment(courseAssignment, assignmentName);
CSVAssignment.verifyAssignmentCsv(picked);
break;
case 15:
......@@ -304,7 +314,7 @@ public class Student extends Role {
System.out.println("Pick an assignment to update: ");
assignmentList.listToString(assignmentList.getAssignmentList());
assignmentsPicked = in.next().split("");
String[] assignmentsPicked = in.next().split("");
System.out.println("Picked: ");
for (String s: assignmentsPicked) {
System.out.println(s + " " + assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName());
......@@ -316,9 +326,9 @@ public class Student extends Role {
assignment.setDueDate(dueDate);
String courseAssignment = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentCourse().getCourseName();
String assignmentName = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName();
validateAssignment(courseAssignment, assignmentName);
String courseAssignment2 = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentCourse().getCourseName();
String assignmentName2 = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName();
validateAssignment(courseAssignment2, assignmentName2);
}
break;
......
......@@ -5,6 +5,7 @@ import Softeng.Group3.SiJadwal.model.Assignment;
import Softeng.Group3.SiJadwal.model.Course;
import Softeng.Group3.SiJadwal.model.Timetable;
import Softeng.Group3.SiJadwal.repository.AssignmentList;
import Softeng.Group3.SiJadwal.repository.CSVAssignment;
import Softeng.Group3.SiJadwal.repository.CourseList;
import Softeng.Group3.SiJadwal.repository.TimetableList;
......@@ -113,15 +114,22 @@ public class TeachingAssistant extends Role {
case 8:
System.out.println("Pick the assignment that you want to validate:");
retrieveAllAssignment();
String[] assignmentsPicked = in.next().split("");
System.out.println("Picked: ");
for (String s: assignmentsPicked) {
System.out.println(s + " " + assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName());
String courseAssignment = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentCourse().getCourseName();
String assignmentName = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName();
validateAssignment(courseAssignment, assignmentName);
int cnt = 1;
for(Assignment s : assignmentList.getAssignmentList()){
System.out.println(cnt + ". " + s.getAssignmentName());
cnt++;
}
String assignmentPicked = in.next();
Assignment picked = assignmentList.getAssignmentList().get(Integer.parseInt(assignmentPicked) - 1);
System.out.println("Picked: " + picked.getAssignmentName());
String courseAssignment = picked.getAssignmentCourse().getCourseName();
String assignmentName = picked.getAssignmentName();
validateAssignment(courseAssignment, assignmentName);
CSVAssignment.verifyAssignmentCsv(picked);
break;
case 9:
......
package Softeng.Group3.SiJadwal.repository;
import Softeng.Group3.SiJadwal.actor.User;
import Softeng.Group3.SiJadwal.model.Assignment;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Time;
import java.time.LocalDate;
import java.util.*;
public class CSVAssignment {
public static void writeAssignment(Assignment assg) {
try{
FileWriter reader = new FileWriter("Assignments.csv", true);
BufferedReader check = new BufferedReader(new FileReader("Assignments.csv"));
String row;
HashMap<String, String> coursesCSV = new HashMap<>();
while((row = check.readLine()) != null){
String[] usersWritten;
usersWritten = row.split(",");
coursesCSV.put(usersWritten[0], usersWritten[1]);
}
if(!coursesCSV.containsKey(assg.getAssignmentName())){
reader.append(assg.getAssignmentName()).append(",")
.append(assg.getCreatedBy().getUsername()).append(",")
.append(assg.getAssignmentCourse().getCourseName()).append(",")
.append(assg.getDueDate().toString()).append(",")
.append(assg.getValidated().toString());
for(User s : assg.getValidatedBy()){
reader.append(",").append(s.getUsername());
}reader.append("\n");
}
reader.flush();
reader.close();
check.close();
}
catch (IOException e) {
System.out.println("File not found.");
e.printStackTrace();
}
}
public static void verifyAssignmentCsv(Assignment assg){
try{
BufferedReader check = new BufferedReader(new FileReader("Assignments.csv"));
String row;
List<String> newList = new ArrayList<>();
while((row = check.readLine()) != null){
String[] assgWritten = row.split(",");
if((assgWritten[0].equalsIgnoreCase(assg.getAssignmentName()) && assgWritten[2].equalsIgnoreCase(assg.getAssignmentCourse().getCourseName()))){
assgWritten[4] = assg.getValidated().toString();
}
newList.add(assgWritten[0]);
for(int i = 1; i < 5; i++) {
newList.add(",");
newList.add(assgWritten[i]);
}
for(User s : assg.getValidatedBy()){
newList.add(",");
newList.add(s.getUsername());
}
newList.add("\n");
} check.close();
FileWriter reader = new FileWriter("Assignments.csv");
for (String s : newList) {
reader.append(s);
}reader.flush();
reader.close();
}
catch (IOException e) {
System.out.println("File not found.");
e.printStackTrace();
}
}
public static void deleteAssignment(String name){
try{
BufferedReader check = new BufferedReader(new FileReader("Assignments.csv"));
String row;
List<String> newList = new ArrayList<>();
while((row = check.readLine()) != null){
String[] courseWritten = row.split(",");
if(!courseWritten[0].equalsIgnoreCase(name)){
newList.add(courseWritten[0]);
for(int i = 1; i < courseWritten.length; i++) {
newList.add(",");
newList.add(courseWritten[i]);
}
newList.add("\n");
}
} check.close();
FileWriter reader = new FileWriter("Assignments.csv");
for (String s : newList) {
reader.append(s);
}reader.flush();
reader.close();
}
catch (IOException e) {
System.out.println("File not found.");
e.printStackTrace();
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment