Fakultas Ilmu Komputer UI

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

CRUD Timetable and CSV Fix

parent ad1e5d07
Pipeline #81794 failed with stages
in 17 seconds
st,t1,rpl,adpro,daa
student,mytable,rpl,adpro
student,table,rpl,daa
student,table,rpl,adpro
student,nama,rpl,adpro
student,yes,rpl,adpro
student,yes,rpl,adpro
student,name,rpl,adpro
student,name,rpl,adpro
student,name,rpl,adpro
student,name,rpl,adpro
student,name,rpl,adpro
student,name,rpl,adpro
student,table,rpl,adpro
student,ame,rpl,adpro
student,name,rpl,adpro
student,name,rpl,adpro
student,table,rpl,adpro
student2,table2,rpl
student,name,rpl,adpro
orang,name,rpl,adpro
orang,table,rpl,adpro
student,name,rpl,adpro
orang,name,rpl,adpro
student,name,rpl,adpro
\ No newline at end of file
st,t1,rpl
admin,Admin
st,Student
ta,Teaching Assistant
A,Student
B,Student
C,Student
student,Student
student2,Student
orang,Student
......@@ -5,6 +5,7 @@ import Softeng.Group3.SiJadwal.actor.RoleType;
import Softeng.Group3.SiJadwal.actor.User;
import Softeng.Group3.SiJadwal.repository.CSVOperator;
import Softeng.Group3.SiJadwal.repository.CourseList;
import Softeng.Group3.SiJadwal.repository.TimetableList;
import Softeng.Group3.SiJadwal.repository.UserList;
import Softeng.Group3.SiJadwal.utility.InputReader;
......@@ -20,6 +21,7 @@ public class Main {
private static UserList userList = new UserList();
private static CourseList courseList = new CourseList();
private static TimetableList timetableList = new TimetableList();
public static Boolean isRunning = true;
......@@ -94,7 +96,7 @@ public class Main {
public static void main(String[] args) {
CSVOperator.InitUsersCourses(userList, courseList);
CSVOperator.InitUsersCourses(userList, courseList, timetableList);
while (isRunning) {
System.out.println("ON-BOARDING");
......
......@@ -3,23 +3,14 @@ package Softeng.Group3.SiJadwal.actor;
import Softeng.Group3.SiJadwal.model.Course;
import Softeng.Group3.SiJadwal.model.Timetable;
import Softeng.Group3.SiJadwal.model.Assignment;
import Softeng.Group3.SiJadwal.repository.CourseList;
import Softeng.Group3.SiJadwal.repository.*;
import Softeng.Group3.SiJadwal.Main;
import Softeng.Group3.SiJadwal.repository.TimetableList;
<<<<<<< HEAD
import Softeng.Group3.SiJadwal.repository.CSVTimetable;
import java.util.HashMap;
import java.util.List;
=======
import Softeng.Group3.SiJadwal.repository.AssignmentList;
import Softeng.Group3.SiJadwal.repository.UserList;
import java.sql.Time;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
>>>>>>> a83b6d2a211d37b5a85e663de2aaacea9a35b505
public class Student extends Role {
......@@ -28,10 +19,7 @@ public class Student extends Role {
private CourseList courseList = new CourseList();
private TimetableList timetableList = new TimetableList();
private AssignmentList assignmentList = new AssignmentList();
// User currentUser = Main.currentUser;
<<<<<<< HEAD
=======
private String assignmentName;
private Course assignmentCourse;
private LocalDate dueDate;
......@@ -39,23 +27,16 @@ public class Student extends Role {
private Set<User> validatedBy = new HashSet<>();
private User createdBy;
>>>>>>> a83b6d2a211d37b5a85e663de2aaacea9a35b505
@Override
public void exclusiveActions() {
System.out.println("6. Create a timetable");
System.out.println("7. See the list of timetable");
System.out.println("8. Add Course to a timetable");
<<<<<<< HEAD
System.out.println("9. Delete a Course in a timetable");
System.out.println("10. Find a timetable");
System.out.println("11. Delete a timetable");
=======
System.out.println("9. Find a timetable");
System.out.println("10. Delete a timetable");
System.out.println("11. Add an assignment");
System.out.println("12. See the list of assignment");
>>>>>>> a83b6d2a211d37b5a85e663de2aaacea9a35b505
System.out.println("12. Add an assignment");
System.out.println("13. See the list of assignments");
}
@Override
......@@ -68,6 +49,8 @@ public class Student extends Role {
System.out.println("Create a new timetable");
System.out.println("===============================");
TimetableList TimeList = new TimetableList();
Timetable newTimetable;
System.out.println("Timetable Name?");
......@@ -82,7 +65,6 @@ public class Student extends Role {
newTimetable = new Timetable();
newTimetable.setTimetableName(timetableName);
newTimetable.setOwner(Main.currentUser);
System.out.println(Main.currentUser.getUsername());
// Set Timetable owner
System.out.println("Pick some courses to add (Comma separated): ");
......@@ -99,9 +81,9 @@ public class Student extends Role {
System.out.println("Timetable created: ");
System.out.println(newTimetable.getTimetableName());
int i = 1;
int counter = 1;
for (Course c: newTimetable.getCourses()) {
System.out.println(i++ + ". " + c.getCourseName());
System.out.println(counter++ + ". " + c.getCourseName());
}
timetableList.addTimetable(timetableName, newTimetable);
......@@ -124,16 +106,36 @@ public class Student extends Role {
System.out.println("Timetable Name?");
timetableName = in.next();
System.out.println("Pick some courses to add (Comma separated): ");
Timetable table = timetableList.getTimetable(timetableName, Main.currentUser);
if(table.getTimetableName() == null){
System.out.println("The table doesn't exists");
return;
}
System.out.println("Pick a courses to add: ");
courseList.listToString(courseList.getCourseList());
coursesPicked = in.next().split(",");
System.out.println("Picked: ");
for (String s: coursesPicked) {
System.out.println(s + ". " + courseList.getCourseList().get(Integer.parseInt(s) - 1).getCourseName());
timetableList.getTimetable(timetableName, Main.currentUser).addCourse(
courseList.getCourseList().get(Integer.parseInt(s) - 1));
String picked = in.next();
List<Course> tableCourse = table.getCourses();
boolean addExists = false;
for (Course course : tableCourse) {
if (courseList.getCourseList().get(Integer.parseInt(picked) - 1).getCourseName().equalsIgnoreCase(course.getCourseName())) {
addExists = true;
break;
}
}
if(addExists){
System.out.println("The course already exists");
return;
}
timetableList.getTimetable(timetableName, Main.currentUser).addCourse(courseList.getCourseList().get(Integer.parseInt(picked) - 1));
System.out.println("Picked: " + courseList.getCourseList().get(Integer.parseInt(picked) - 1).getCourseName());
System.out.println("Timetable created: ");
System.out.println(timetableList.getTimetable(timetableName, Main.currentUser).getTimetableName());
......@@ -161,23 +163,34 @@ public class Student extends Role {
timetableName = in.next();
Timetable table = timetableList.getTimetable(timetableName, Main.currentUser);
List<Course> exist2 = table.getCourses();
if(table == null){
if(table.getTimetableName() == null){
System.out.println("The table doesn't exists");
return;
}
System.out.println("Pick one or more courses to delete (Comma separated): ");
System.out.println("Pick a courses to delete: ");
courseList.listToString(courseList.getCourseList());
coursesPicked = in.next().split(",");
System.out.println("Picked: ");
for (String s: coursesPicked) {
System.out.println(s + ". " + courseList.getCourseList().get(Integer.parseInt(s) - 1).getCourseName());
timetableList.getTimetable(timetableName, Main.currentUser).deleteCourse(
courseList.getCourseList().get(Integer.parseInt(s) - 1));
String picked = in.next();
List<Course> tableCourse = table.getCourses();
boolean delExists = false;
for (Course course : tableCourse) {
if (courseList.getCourseList().get(Integer.parseInt(picked) - 1).getCourseName().equalsIgnoreCase(course.getCourseName())) {
delExists = true;
break;
}
}
if(!delExists){
System.out.println("The course does not exists");
return;
}
System.out.println("Picked: " + courseList.getCourseList().get(Integer.parseInt(picked) - 1).getCourseName());
timetableList.getTimetable(timetableName, Main.currentUser).deleteCourse(courseList.getCourseList().get(Integer.parseInt(picked) - 1));
System.out.println("Timetable updated: ");
System.out.println(timetableList.getTimetable(timetableName, Main.currentUser).getTimetableName());
......@@ -217,7 +230,7 @@ public class Student extends Role {
Timetable delTable = timetableList.getTimetable(tableDel, Main.currentUser);
if(delTable == null){
if(delTable.getTimetableName() == null){
System.out.println("The timetable does not exist");
return;
}
......@@ -227,7 +240,7 @@ public class Student extends Role {
System.out.println("Timetable deleted.");
break;
case 11:
case 12:
System.out.println("Add an assignment: ");
System.out.println("===============================");
......@@ -249,7 +262,6 @@ public class Student extends Role {
System.out.println("Enter due date: yyyy-MM-dd");
String date = in.next();
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
dueDate = LocalDate.parse(date);
assignment.setDueDate(dueDate);
......@@ -262,7 +274,7 @@ public class Student extends Role {
break;
case 12:
case 13:
try {
assignmentList.listToString(assignmentList.getAssignmentList());
break;
......@@ -271,6 +283,7 @@ public class Student extends Role {
break;
}
default:
}
}
......
......@@ -3,9 +3,11 @@ package Softeng.Group3.SiJadwal.repository;
import java.io.*;
import java.sql.Time;
import Softeng.Group3.SiJadwal.actor.RoleType;
import Softeng.Group3.SiJadwal.model.Course;
import Softeng.Group3.SiJadwal.model.Timetable;
public class CSVOperator {
public static void InitUsersCourses(UserList userlist, CourseList courselist){
public static void InitUsersCourses(UserList userlist, CourseList courselist, TimetableList timetableList){
try{
BufferedReader check = new BufferedReader(new FileReader("Users.csv"));
String row;
......@@ -16,13 +18,27 @@ public class CSVOperator {
}
check.close();
BufferedReader check2 = new BufferedReader(new FileReader("Courses.csv"));
while((row = check2.readLine()) != null){
check = new BufferedReader(new FileReader("Courses.csv"));
while((row = check.readLine()) != null){
String[] courses;
courses = row.split(",");
courselist.addCourse(courses[0], courses[1], Time.valueOf(courses[2]), Time.valueOf(courses[3]));
}
check2.close();
check.close();
check = new BufferedReader(new FileReader("Timetable.csv"));
while((row = check.readLine()) != null){
String[] tables;
tables = row.split(",");
Timetable newTable = new Timetable();
newTable.setTimetableName(tables[1]);
newTable.setOwner(userlist.getUser(tables[0]));
for(int i = 2; i < tables.length; i++){
newTable.addCourse(courselist.getCourse(tables[i]));
}
timetableList.addTimetable(tables[0], newTable);
}
check.close();
}
catch (IOException e) {
System.out.println("File not found.");
......
......@@ -2,6 +2,7 @@ package Softeng.Group3.SiJadwal.repository;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
......@@ -45,27 +46,14 @@ public class CSVTimetable {
List<String> newList = new ArrayList<>();
while((row = check.readLine()) != null){
String[] tableWritten = row.split(",");
int counter = 0;
if(tableWritten[0].equalsIgnoreCase(name) && tableWritten[1].equalsIgnoreCase(table)){
for(int i = 2; i < tableWritten.length; i++, counter++){
tableWritten[i] = newCourse.get(i-2).getCourseName();
}if(counter <= newCourse.size()-1){
newList.add(tableWritten[0]);
for(int i = 1; i < tableWritten.length; i++) {
newList.add(",");
newList.add(tableWritten[i]);
}for(int i = counter; i < newCourse.size(); i++){
newList.add(",");
newList.add(newCourse.get(i).getCourseName());
}
newList.add("\n");
}else{
newList.add(tableWritten[0]);
for(int i = 1; i < tableWritten.length; i++) {
newList.add(",");
newList.add(tableWritten[i]);
}
newList.add("\n");
List<String> toCSV = new ArrayList<>(Arrays.asList(tableWritten));
if(toCSV.get(0).equalsIgnoreCase(name) && toCSV.get(1).equalsIgnoreCase(table)){
newList.add(tableWritten[0]);
newList.add(",");
newList.add(tableWritten[1]);
for(Course c : newCourse){
newList.add(",");
newList.add(c.getCourseName());
}
}else{
newList.add(tableWritten[0]);
......@@ -73,8 +61,8 @@ public class CSVTimetable {
newList.add(",");
newList.add(tableWritten[i]);
}
newList.add("\n");
}
newList.add("\n");
} check.close();
FileWriter reader = new FileWriter("Timetable.csv");
for (String s : newList) {
......
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