Fakultas Ilmu Komputer UI

Commit 408401d2 authored by Bagus Prabowo's avatar Bagus Prabowo
Browse files

File Structure Fix

parent c990f6e9
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();
}
}
}
......@@ -34,169 +34,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){
......
......@@ -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