Fakultas Ilmu Komputer UI

Commit 7f50d30f authored by Bagus Prabowo's avatar Bagus Prabowo
Browse files

Merge branch 'bagus2' into 'master'

Bagus2

See merge request !6
parents 7b8c673e eb47ddbe
admin,Admin
st,Student
ta,Teaching Assistant
\ No newline at end of file
ta,Teaching Assistant
......@@ -27,6 +27,7 @@ public class Student extends Role {
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");
}
@Override
......@@ -39,28 +40,29 @@ 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();
newTimetable = timetableList.getTimetable(timetableName, Main.currentUser);
if (newTimetable != null) {
System.out.println("Timetable exists.. Updating..");
} else {
System.out.println("Creating new Timetable...");
newTimetable = new Timetable();
newTimetable.setTimetableName(timetableName);
newTimetable.setOwner(Main.currentUser);
System.out.println(Main.currentUser.getUsername());
if(timetableList.getTimetable(timetableName, Main.currentUser) != null){
System.out.println("The user does not exist");
return;
}
System.out.println("Creating new Timetable...");
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): ");
courseList.listToString(courseList.getCourseList());
// Reset maybe?
String[] coursesPicked = null;
coursesPicked = in.next().split(",");
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());
......@@ -73,7 +75,7 @@ public class Student extends Role {
System.out.println(newTimetable.getTimetableName());
int i = 1;
for (Course c: newTimetable.getCourses()) {
System.out.println(i++ + " " + c.getCourseName());
System.out.println(i++ + ". " + c.getCourseName());
}
timetableList.addTimetable(newTimetable);
......@@ -133,6 +135,22 @@ public class Student extends Role {
break;
}
case 10:
TimetableList delTable = new TimetableList();
System.out.println("Please enter the timetable name that you want to delete: ");
String tableDel = in.next();
if(delTable.getTimetable(tableDel, Main.currentUser) == null){
System.out.println("The timetable does not exist");
return;
}
delTable.deleteTimetable("tableDel");
System.out.println("Timetable deleted.");
break;
default:
}
}
......
package Softeng.Group3.SiJadwal.repository;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Time;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class CSVCourse {
public static void writeCourse(String name, String lecturer, Time start, Time end) {
try{
FileWriter reader = new FileWriter("Courses.csv", true);
BufferedReader check = new BufferedReader(new FileReader("Courses.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(name)){
reader.append(name).append(",").append(lecturer).append(",")
.append(start.toString()).append(",").append(end.toString()).append("\n");
}
reader.flush();
reader.close();
check.close();
}
catch (IOException e) {
System.out.println("File not found.");
e.printStackTrace();
}
}
public static void updateCourse(String name, String lecturer, Time start, Time end){
try{
BufferedReader check = new BufferedReader(new FileReader("Courses.csv"));
String row;
List<String> newList = new ArrayList<>();
while((row = check.readLine()) != null){
String[] usersWritten = row.split(",");
if(usersWritten[0].equalsIgnoreCase(name)){
usersWritten[1] = lecturer;
usersWritten[2] = start.toString();
usersWritten[3] = end.toString();
}
newList.add(usersWritten[0]);
newList.add(",");
newList.add(usersWritten[1]);
newList.add(",");
newList.add(usersWritten[2]);
newList.add(",");
newList.add(usersWritten[3]);
newList.add("\n");
} check.close();
FileWriter reader = new FileWriter("Courses.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 deleteCourse(String name){
try{
BufferedReader check = new BufferedReader(new FileReader("Courses.csv"));
String row;
List<String> newList = new ArrayList<>();
while((row = check.readLine()) != null){
String[] usersWritten = row.split(",");
if(!usersWritten[0].equalsIgnoreCase(name)){
newList.add(usersWritten[0]);
newList.add(",");
newList.add(usersWritten[1]);
newList.add(",");
newList.add(usersWritten[2]);
newList.add(",");
newList.add(usersWritten[3]);
newList.add("\n");
}
} check.close();
FileWriter reader = new FileWriter("Courses.csv");
for (String s : newList) {
reader.append(s);
}reader.flush();
reader.close();
}
catch (IOException e) {
System.out.println("File not found.");
e.printStackTrace();
}
}
}
......@@ -2,10 +2,6 @@ package Softeng.Group3.SiJadwal.repository;
import java.io.*;
import java.sql.Time;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import Softeng.Group3.SiJadwal.actor.RoleType;
public class CSVOperator {
......@@ -34,169 +30,4 @@ public class CSVOperator {
}
}
public static void writeUser(String Uname, String Type) {
try{
FileWriter reader = new FileWriter("Users.csv", true);
BufferedReader check = new BufferedReader(new FileReader("Users.csv"));
String row;
HashMap<String, String> usersCSV = new HashMap<>();
while((row = check.readLine()) != null){
String[] usersWritten;
usersWritten = row.split(",");
usersCSV.put(usersWritten[0], usersWritten[1]);
}
if(!usersCSV.containsKey(Uname)){
reader.append(Uname).append(",").append(Type).append("\n");
}
reader.flush();
reader.close();
check.close();
}
catch (IOException e) {
System.out.println("File not found.");
e.printStackTrace();
}
}
public static void writeCourse(String name, String lecturer, Time start, Time end) {
try{
FileWriter reader = new FileWriter("Courses.csv", true);
BufferedReader check = new BufferedReader(new FileReader("Courses.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(name)){
reader.append(name).append(",").append(lecturer).append(",")
.append(start.toString()).append(",").append(end.toString()).append("\n");
}
reader.flush();
reader.close();
check.close();
}
catch (IOException e) {
System.out.println("File not found.");
e.printStackTrace();
}
}
public static void updateUser(String Uname, String newType){
try{
BufferedReader check = new BufferedReader(new FileReader("Users.csv"));
String row;
List<String> newList = new ArrayList<>();
while((row = check.readLine()) != null){
String[] usersWritten = row.split(",");
if(usersWritten[0].equalsIgnoreCase(Uname)){
usersWritten[1] = newType;
}
newList.add(usersWritten[0]);
newList.add(",");
newList.add(usersWritten[1]);
newList.add("\n");
} check.close();
FileWriter reader = new FileWriter("Users.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 deleteUser(String Uname){
try{
BufferedReader check = new BufferedReader(new FileReader("Users.csv"));
String row;
List<String> newList = new ArrayList<>();
while((row = check.readLine()) != null){
String[] usersWritten = row.split(",");
if(!usersWritten[0].equalsIgnoreCase(Uname)){
newList.add(usersWritten[0]);
newList.add(",");
newList.add(usersWritten[1]);
newList.add("\n");
}
} check.close();
FileWriter reader = new FileWriter("Users.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 updateCourse(String name, String lecturer, Time start, Time end){
try{
BufferedReader check = new BufferedReader(new FileReader("Courses.csv"));
String row;
List<String> newList = new ArrayList<>();
while((row = check.readLine()) != null){
String[] usersWritten = row.split(",");
if(usersWritten[0].equalsIgnoreCase(name)){
usersWritten[1] = lecturer;
usersWritten[2] = start.toString();
usersWritten[3] = end.toString();
}
newList.add(usersWritten[0]);
newList.add(",");
newList.add(usersWritten[1]);
newList.add(",");
newList.add(usersWritten[2]);
newList.add(",");
newList.add(usersWritten[3]);
newList.add("\n");
} check.close();
FileWriter reader = new FileWriter("Courses.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 deleteCourse(String name){
try{
BufferedReader check = new BufferedReader(new FileReader("Courses.csv"));
String row;
List<String> newList = new ArrayList<>();
while((row = check.readLine()) != null){
String[] usersWritten = row.split(",");
if(!usersWritten[0].equalsIgnoreCase(name)){
newList.add(usersWritten[0]);
newList.add(",");
newList.add(usersWritten[1]);
newList.add(",");
newList.add(usersWritten[2]);
newList.add(",");
newList.add(usersWritten[3]);
newList.add("\n");
}
} check.close();
FileWriter reader = new FileWriter("Courses.csv");
for (String s : newList) {
reader.append(s);
}reader.flush();
reader.close();
}
catch (IOException e) {
System.out.println("File not found.");
e.printStackTrace();
}
}
}
package Softeng.Group3.SiJadwal.repository;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class CSVUser {
public static void writeUser(String Uname, String Type) {
try{
FileWriter reader = new FileWriter("Users.csv", true);
BufferedReader check = new BufferedReader(new FileReader("Users.csv"));
String row;
HashMap<String, String> usersCSV = new HashMap<>();
while((row = check.readLine()) != null){
String[] usersWritten;
usersWritten = row.split(",");
usersCSV.put(usersWritten[0], usersWritten[1]);
}
if(!usersCSV.containsKey(Uname)){
reader.append(Uname).append(",").append(Type).append("\n");
}
reader.flush();
reader.close();
check.close();
}
catch (IOException e) {
System.out.println("File not found.");
e.printStackTrace();
}
}
public static void updateUser(String Uname, String newType){
try{
BufferedReader check = new BufferedReader(new FileReader("Users.csv"));
String row;
List<String> newList = new ArrayList<>();
while((row = check.readLine()) != null){
String[] usersWritten = row.split(",");
if(usersWritten[0].equalsIgnoreCase(Uname)){
usersWritten[1] = newType;
}
newList.add(usersWritten[0]);
newList.add(",");
newList.add(usersWritten[1]);
newList.add("\n");
} check.close();
FileWriter reader = new FileWriter("Users.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 deleteUser(String Uname){
try{
BufferedReader check = new BufferedReader(new FileReader("Users.csv"));
String row;
List<String> newList = new ArrayList<>();
while((row = check.readLine()) != null){
String[] usersWritten = row.split(",");
if(!usersWritten[0].equalsIgnoreCase(Uname)){
newList.add(usersWritten[0]);
newList.add(",");
newList.add(usersWritten[1]);
newList.add("\n");
}
} check.close();
FileWriter reader = new FileWriter("Users.csv");
for (String s : newList) {
reader.append(s);
}reader.flush();
reader.close();
}
catch (IOException e) {
System.out.println("File not found.");
e.printStackTrace();
}
}
}
......@@ -30,7 +30,7 @@ public class CourseList {
newCourse.setStartTime(startTime);
newCourse.setEndTime(endTime);
courseList.add(newCourse);
CSVOperator.writeCourse(courseName, lecturer, startTime, endTime);
CSVCourse.writeCourse(courseName, lecturer, startTime, endTime);
}
public void updateCourse(String courseName, String lecturer, Time startTime, Time endTime){
......@@ -42,13 +42,13 @@ public class CourseList {
newCourse.setStartTime(startTime);
newCourse.setEndTime(endTime);
courseList.set(index, newCourse);
CSVOperator.updateCourse(courseName, lecturer,startTime, endTime);
CSVCourse.updateCourse(courseName, lecturer,startTime, endTime);
}
public void deleteCourse(String name){
Course delCourse = getCourse(name);
courseList.remove(delCourse);
CSVOperator.deleteCourse(name);
CSVCourse.deleteCourse(name);
}
public void listToString(List<Course> courseList){
......
package Softeng.Group3.SiJadwal.repository;
import Softeng.Group3.SiJadwal.Main;
import Softeng.Group3.SiJadwal.actor.RoleType;
import Softeng.Group3.SiJadwal.actor.User;
import Softeng.Group3.SiJadwal.model.Course;
......@@ -50,4 +51,9 @@ public class TimetableList {
}
}
public void deleteTimetable(String table){
Timetable delTable = getTimetable(table, Main.currentUser);
allTimetableList.remove(delTable);
}
}
......@@ -29,7 +29,7 @@ public class UserList {
newUser.setUsername(username);
newUser.setRole(role);
userList.add(newUser);
CSVOperator.writeUser(username, RoleType.RoletoString(role));
CSVUser.writeUser(username, RoleType.RoletoString(role));
}
public void updateRole(String username, RoleType role){
......@@ -39,13 +39,13 @@ public class UserList {
updated.setRole(role);
updated.setUsername(username);
userList.set(index, updated);
CSVOperator.updateUser(username, RoleType.RoletoString(role));
CSVUser.updateUser(username, RoleType.RoletoString(role));
}
public void deleteUser(String Uname){
User delUser = getUser(Uname);
userList.remove(delUser);
CSVOperator.deleteUser(Uname);
CSVUser.deleteUser(Uname);
}
public void listToString(List<User> userList){
......
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