Fakultas Ilmu Komputer UI

Commit 4cb87ef6 authored by hazlazuardi's avatar hazlazuardi
Browse files

Validate assignment not done yet

parents 1d9f6cbf 2f01c842
Pipeline #81847 passed with stages
in 5 minutes and 1 second
rpl,ade,1:01:01,1:01:02
adpro,daya,5:05:05,7:07:07
daa,there,4:04:04,13:01:01
\ No newline at end of file
daa,there,4:04:04,13:01:01
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
null,A
st,re,rpl,daa
st,re,rpl,adpro
st,rere,rpl,daa
st,rere,rpl,daa
st,hola,rpl
st,re,rpl,adpro
st,2,rpl
st,rere,rpl,daa
st,t1,rpl
admin,Admin
st,Student
ta,Teaching Assistant
A,Student
B,Student
C,Student
student,Student
student2,Student
orang,Student
Test,Teaching Assistant
ta,Teaching Assistant
\ No newline at end of file
File mode changed from 100755 to 100644
......@@ -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 {
public 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,17 +3,15 @@ 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;
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.*;
public class Student extends Role {
private String timetableName;
......@@ -21,7 +19,6 @@ public class Student extends Role {
private CourseList courseList = new CourseList();
private TimetableList timetableList = new TimetableList();
private AssignmentList assignmentList = new AssignmentList();
// User currentUser = Main.currentUser;
private String assignmentName;
private Course assignmentCourse;
......@@ -30,57 +27,19 @@ public class Student extends Role {
private Set<User> validatedBy = new HashSet<>();
private User createdBy;
private Timetable createTimetable(String timetableName, String[] coursesPicked) {
System.out.println("Picked: ");
Timetable newTimetable = new Timetable();
for (String s: coursesPicked) {
System.out.println(s + " " + courseList.getCourseList().get(Integer.parseInt(s) - 1).getCourseName());
newTimetable.addCourse(
courseList.getCourseList().get(Integer.parseInt(s) - 1));
}
newTimetable.setTimetableName(timetableName);
newTimetable.setOwner(Main.currentUser);
timetableList.addTimetable(timetableName, newTimetable);
return newTimetable;
}
private List<Assignment> retrieveAllAssignment() {
try {
assignmentList.listToString(assignmentList.getAssignmentList());
return assignmentList.getAssignmentList();
} catch (NullPointerException e) {
System.out.println("No Assignment");
return null;
}
}
// private Timetable updateTimetable(String element) {
// try {
// Timetable toUpdate = timetableList.getTimetable(timetableName, Main.currentUser);
// return toUpdate;
// } catch (Exception e) {
// System.out.println("Timetable not found");
// }
// return null;
// }
private Assignment validateAssignment(String courseName, String assignmentName) {
Assignment toValidate = courseList.getCourse(courseName).getAssignment(assignmentName);
toValidate.addValidatedBy(Main.currentUser);
return toValidate;
}
@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");
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");
System.out.println("13. Validate Assignment");
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("12. Add an assignment");
System.out.println("13. See the list of assignments");
System.out.println("14. Validate assignments");
System.out.println("15. Update an assignments");
System.out.println("16. Delete an assignments");
}
@Override
......@@ -93,17 +52,44 @@ 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?");
timetableName = in.next();
if(timetableList.getTimetable(timetableName, Main.currentUser) != null){
System.out.println("The user does not exist");
System.out.println("The table already exists.");
return;
}
System.out.println("Creating new Timetable...");
newTimetable = new Timetable();
newTimetable.setTimetableName(timetableName);
newTimetable.setOwner(Main.currentUser);
// Set Timetable owner
System.out.println("Pick some courses to add (Comma separated): ");
courseList.listToString(courseList.getCourseList());
// Reset maybe?
String[] coursesPicked = in.next().split(",");
createTimetable(timetableName, coursesPicked);
System.out.println("Picked: ");
for (String s: coursesPicked) {
System.out.println(s + " " + courseList.getCourseList().get(Integer.parseInt(s) - 1).getCourseName());
newTimetable.addCourse(
courseList.getCourseList().get(Integer.parseInt(s) - 1));
}
System.out.println("Timetable created: ");
System.out.println(newTimetable.getTimetableName());
int counter = 1;
for (Course c: newTimetable.getCourses()) {
System.out.println(counter++ + ". " + c.getCourseName());
}
timetableList.addTimetable(timetableName, newTimetable);
break;
case 7:
......@@ -123,22 +109,47 @@ 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());
List<Course> addCourse = timetableList.getTimetable(timetableName, Main.currentUser).getCourses();
int j = 1;
for (Course c: timetableList.getTimetable(timetableName, Main.currentUser).getCourses()) {
System.out.println(j++ + " " + c.getCourseName());
for (Course c: addCourse) {
System.out.println(j++ + ". " + c.getCourseName());
}
CSVTimetable.updateCourseTimetable(Main.currentUser.getUsername(), timetableName, addCourse);
break;
} catch (NullPointerException e) {
......@@ -146,8 +157,63 @@ public class Student extends Role {
break;
}
case 9:
try {
System.out.println("Delete a course in a timetable");
System.out.println("===============================");
System.out.println("Timetable Name?");
timetableName = in.next();
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 delete: ");
courseList.listToString(courseList.getCourseList());
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());
List<Course> delCourse = timetableList.getTimetable(timetableName, Main.currentUser).getCourses();
int j = 1;
for (Course c: delCourse) {
System.out.println(j++ + ". " + c.getCourseName());
}
CSVTimetable.updateCourseTimetable(Main.currentUser.getUsername(), timetableName, delCourse);
break;
} catch (NullPointerException e) {
System.out.println("Timetable not found");
break;
}
case 10:
System.out.println("Find timetable by name: ");
try {
String timetableName = in.next();
......@@ -160,14 +226,14 @@ public class Student extends Role {
break;
}
case 10:
case 11:
System.out.println("Please enter the timetable name that you want to delete: ");
String tableDel = in.next();
Timetable delTable = timetableList.getTimetable(tableDel, Main.currentUser);
if(delTable == null){
if(delTable.getTimetableName() == null){
System.out.println("The timetable does not exist");
return;
}
......@@ -177,7 +243,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("===============================");
......@@ -199,7 +265,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);
......@@ -212,22 +277,77 @@ public class Student extends Role {
break;
case 12:
retrieveAllAssignment();
case 13:
try {
assignmentList.listToString(assignmentList.getAssignmentList());
break;
} catch (NullPointerException e) {
System.out.println("No Assignment");
break;
}
case 14:
System.out.println("Pick the assignment that you want to validate:");
assignmentList.listToString(assignmentList.getAssignmentList());
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);
}
break;
case 13:
System.out.println("Pick the assignment that you want to validate: (Write the name)");
System.out.println(courseList.getCourse("rpl").getAssignments().toString());
System.out.println("");
String nameToVaidate = in.next();
String courseToValidate = in.next();
case 15:
System.out.println("Update an assignment: ");
System.out.println("===============================");
System.out.println("Pick an assignment to update: ");
assignmentList.listToString(assignmentList.getAssignmentList());
assignmentsPicked = in.next().split("");
System.out.println("Picked: ");
for (String s: assignmentsPicked) {
System.out.println(s + " " + assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName());
assignment = assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1);
System.out.println("Enter new due date: yyyy-MM-dd");
String updateDate = in.nextLine();
dueDate = LocalDate.parse(updateDate);
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);
}
break;
case 16:
System.out.println("Pick an assignment to delete: ");
assignmentsPicked = in.next().split("");
System.out.println("Picked: ");
for (String s: assignmentsPicked) {
System.out.println(s + " " + assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentName());
assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1).getAssignmentCourse().
deleteAssignment(assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1));
assignmentList.deleteAssignment(assignmentList.getAssignmentList().get(Integer.parseInt(s) - 1));
System.out.println("Assignment deleted.");
break;
}
default:
}
}
private void validateAssignment(String courseName, String assignmentName) {
Assignment toValidate = courseList.getCourse(courseName).getAssignment(assignmentName);
toValidate.addValidatedBy(Main.currentUser);
}
public HashMap<String, Course> listToHashmap(List<Course> list){
HashMap<String, Course> hashMap = new HashMap<>();
......
package Softeng.Group3.SiJadwal.actor;
import Softeng.Group3.SiJadwal.Main;
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.CourseList;
import Softeng.Group3.SiJadwal.repository.TimetableList;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TeachingAssistant extends Role {
private String timetableName;
private HashMap<String, Course> courseOptions;
private CourseList courseList = new CourseList();
private TimetableList timetableList = new TimetableList();
private AssignmentList assignmentList = new AssignmentList();
private String assignmentName;
private Course assignmentCourse;
private LocalDate dueDate;
private Boolean validated;
private Set<User> validatedBy = new HashSet<>();
private User createdBy;
private List<Assignment> retrieveAllAssignment() {
try {
assignmentList.listToString(assignmentList.getAssignmentList());
return assignmentList.getAssignmentList();
} catch (NullPointerException e) {
System.out.println("No Assignment");
return null;
}
}
private Assignment validateAssignment(String courseName, String assignmentName) {
Assignment toValidate = courseList.getCourse(courseName).getAssignment(assignmentName);
toValidate.addValidatedBy(Main.currentUser);
validated = toValidate.getValidated();
toValidate.setValidated((validated));
return toValidate;
}
@Override
public void exclusiveActions() {
System.out.println("6. Add an assignment");
System.out.println("7. See the list of assignment");
System.out.println("8. Validate assignment");
System.out.println("9. Update assignment");
System.out.println("10. Delete Assignment");
}
@Override
public void doExclusiveActions(int userAction) {
courseOptions = listToHashmap(courseList.getCourseList());
switch (userAction){
case 6:
System.out.println("Add an assignment: ");
System.out.println("===============================");
Assignment assignment = new Assignment();
System.out.println("Assignment Name?");
assignmentName = in.next();
assignment.setAssignmentName(assignmentName);
System.out.println("Pick a course to add assignment: ");
courseList.listToString(courseList.getCourseList());
String[] coursesPicked = in.next().split("");
System.out.println("Picked: ");
for (String s: coursesPicked) {
System.out.println(s + " " + courseList.getCourseList().get(Integer.parseInt(s) - 1).getCourseName());
assignment.setAssignmentCourse(
courseList.getCourseList().get(Integer.parseInt(s) - 1));
}
System.out.println("Enter due date: yyyy-MM-dd");
String date = in.nextLine();
dueDate = LocalDate.parse(date);
assignment.setDueDate(dueDate);
assignment.setCreatedBy(Main.currentUser);
assignmentList.addAssignment(assignmentName, assignment);
for (String s: coursesPicked) {
courseList.getCourseList().get(Integer.parseInt(s) - 1).addAssignment(assignment);
}
validateAssignment(assignment.getAssignmentCourse().getCourseName(), assignmentName);
break;
case 7:
try {
retrieveAllAssignment();
break;
} catch (NullPointerException e) {
System.out.println("No Assignment");
break;
}
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) {