Fakultas Ilmu Komputer UI

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

CSV fix and addition

parent bcfcc024
rpl,ade01:01:0101:01:01
adpro,daya05:05:0507:07:07
daa,there04:04:0401:01:01
rpl,ade01:01:0101:01:01
adpro,daya05:05:0507:07:07
daa,there04:04:0401:01:01
rpl,ade01:01:0101:01:01
adpro,daya05:05:0507:07:07
daa,there04:04:0401:01:01
rpl,ade01:01:0101:01:01
adpro,daya05:05:0507:07:07
daa,there04:04:0401:01:01
rpl,ade01:01:0101:01:01
adpro,daya05:05:0507:07:07
daa,there04:04:0401:01:01
rpl,ade01:01:0101:01:01
adpro,daya05:05:0507:07:07
daa,there04:04:0401:01:01
rpl,ade01:01:0101:01:01
adpro,daya05:05:0507:07:07
daa,there04:04:0401:01:01
rpl,ade01:01:0101:01:01
adpro,daya05:05:0507:07:07
daa,there04:04:0401:01:01
rpl,ade01:01:0101:01:01
adpro,daya05:05:0507:07:07
daa,there04:04:0401:01:01
rpl,ade01:01:0101:01:01
adpro,daya05:05:0507:07:07
daa,there04:04:0401:01:01
rpl,ade01:01:0101:01:01
adpro,daya05:05:0507:07:07
daa,there04:04:0401:01:01
rpl,ade01:01:0101:01:01
adpro,daya05:05:0507:07:07
daa,there04:04:0401:01:01
rpl,ade01:01:0101:01:01
adpro,daya05:05:0507:07:07
daa,there04:04:0401:01:01
rpl,ade01:01:0101:01:01
adpro,daya05:05:0507:07:07
daa,there04:04:0401:01:01
rpl,ade01:01:0101:01:01
adpro,daya05:05:0507:07:07
daa,there04:04:0401:01:01
rpl,ade01:01:0101:01:01
adpro,daya05:05:0507:07:07
daa,there04:04:0401:01:01
rpl,ade,1:01:01,1:01:02
adpro,daya,5:05:05,7:07:07
daa,there,4:04:04,13:01:01
admin,ADMIN
st,STUDENT
admin,ADMIN
st,STUDENT
admin,ADMIN
st,STUDENT
we,TEACHING_ASSISTANT
admin,ADMIN
st,STUDENT
admin,ADMIN
st,STUDENT
admin,ADMIN
st,STUDENT
admin,ADMIN
st,STUDENT
admin,ADMIN
st,STUDENT
admin,ADMIN
st,STUDENT
admin,ADMIN
st,STUDENT
admin,ADMIN
st,STUDENT
admin,ADMIN
st,STUDENT
admin,ADMIN
st,STUDENT
admin,ADMIN
st,STUDENT
admin,ADMIN
st,STUDENT
admin,ADMIN
st,STUDENT
admin,ADMIN
st,STUDENT
sr,STUDENT
admin,ADMIN
st,STUDENT
sre,STUDENT
admin,Admin
st,Student
ta,Teaching Assistant
......@@ -3,6 +3,7 @@ package Softeng.Group3.SiJadwal;
import Softeng.Group3.SiJadwal.actor.Role;
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.UserList;
import Softeng.Group3.SiJadwal.utility.InputReader;
......@@ -93,11 +94,7 @@ public class Main {
public static void main(String[] args) {
userList.addUser("admin", RoleType.ADMIN);
userList.addUser("st", RoleType.STUDENT);
courseList.addCourse("rpl", "ade", Time.valueOf("1:1:1"), Time.valueOf("1:1:1"));
courseList.addCourse("adpro", "daya", Time.valueOf("5:5:5"), Time.valueOf("7:7:7"));
courseList.addCourse("daa", "there", Time.valueOf("4:4:4"), Time.valueOf("1:1:1"));
CSVOperator.InitUsersCourses(userList, courseList);
while (isRunning) {
System.out.println("ON-BOARDING");
......
......@@ -32,6 +32,11 @@ public class Admin extends Role {
System.out.println("===============================");
System.out.println("Course Name?");
courseName = in.next();
for(int i = 0; i < courseList.getCourseList().size(); i++){
if(courseName == courseList.getCourseList().get(i).getCourseName());
System.out.println("Course already exists");
return;
}
System.out.println("Lecturer Name?");
lecturer = in.next();
System.out.println("Start Time? hour:minute:second");
......
......@@ -16,7 +16,7 @@ public enum RoleType {
}
}
public RoleType StringtoRole(String roleType) {
public static RoleType StringtoRole(String roleType) {
switch (roleType){
case "Student":
return STUDENT;
......
......@@ -4,7 +4,34 @@ import java.io.*;
import java.sql.Time;
import java.util.HashMap;
import Softeng.Group3.SiJadwal.actor.RoleType;
public class CSVOperator {
public static void InitUsersCourses(UserList userlist, CourseList courselist){
try{
BufferedReader check = new BufferedReader(new FileReader("Users.csv"));
String row;
while((row = check.readLine()) != null){
String[] users;
users = row.split(",");
userlist.addUser(users[0], RoleType.StringtoRole(users[1]));
}
check.close();
BufferedReader check2 = new BufferedReader(new FileReader("Courses.csv"));
while((row = check2.readLine()) != null){
String[] courses;
courses = row.split(",");
courselist.addCourse(courses[0], courses[1], Time.valueOf(courses[2]), Time.valueOf(courses[3]));
}
check2.close();
}
catch (IOException e) {
System.out.println("File not found.");
e.printStackTrace();
}
}
public static void writeUser(String Uname, String Type) {
try{
FileWriter reader = new FileWriter("Users.csv", true);
......@@ -23,6 +50,7 @@ public class CSVOperator {
check.close();
}
catch (IOException e) {
System.out.println("File not found.");
e.printStackTrace();
}
}
......@@ -39,13 +67,14 @@ public class CSVOperator {
coursesCSV.put(usersWritten[0], usersWritten[1]);
}
if(!coursesCSV.containsKey(name)){
reader.append(name).append(",").append(lecturer)
.append(start.toString()).append(end.toString()).append("\n");
reader.append(name).append(",").append(lecturer).append(",")
.append(start.toString()).append(",").append(end.toString()).append("\n");
}
reader.close();
check.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