Fakultas Ilmu Komputer UI

Commit 84c7640b authored by saddamonpc's avatar saddamonpc
Browse files

Add persistent storage for CourseList

parent 227e7fa8
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
package softeng.g4;
import softeng.g4.course.Course;
import softeng.g4.course.CourseList;
import softeng.g4.user.Admin;
import softeng.g4.user.Student;
import softeng.g4.user.TeachingAssistant;
import softeng.g4.user.UserList;
import java.io.*;
import java.util.*;
public class Main {
......@@ -20,6 +21,8 @@ public class Main {
String q = "";
String currentLogin = "";
CourseList courseList = openCourseList();
// Uncomment to do testing
TeachingAssistant testTa =
new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"));
......@@ -29,9 +32,20 @@ public class Main {
testTa.setSchedule("saturday", "Busy", "07:00", "21:00");
testTa.setSchedule("sunday", "Free", "12:00", "17:00");
Admin testAdmin = new Admin("akuAdmin", "Aku Admin");
testAdmin.createCourse("Calculus II", "CALC120", "Aku Dosen", 3);
testAdmin.createCourse("Statistika & Probabilita", "STAT69", "Aku Professor", 3);
testAdmin.createCourse("Rekayasa Perangkat Lunak", "RPL9000", "Aku Dosen", 4);
// testAdmin.createCourse("Calculus II", "CALC120", "Aku Dosen", 3);
// testAdmin.createCourse("Statistika & Probabilita", "STAT69", "Aku Professor", 3);
// testAdmin.createCourse("Rekayasa Perangkat Lunak", "RPL9000", "Aku Dosen", 4);
// // Store courselist test
// try {
// FileOutputStream fos = new FileOutputStream("src/softeng/g4/xyz.txt");
// ObjectOutputStream oos = new ObjectOutputStream(fos);
// oos.writeObject(courseList);
//
// } catch (Exception ex) {
// System.out.println("Exception is caught");
// }
while (true) {
......@@ -42,7 +56,7 @@ public class Main {
break;
}
// TODO: Maybe it is better to move this into a different class
// TODO: Maybe it is better to move this whole if block into a different class
checkLogin(q);
currentLogin = q;
......@@ -60,7 +74,7 @@ public class Main {
break;
case "COURSELIST":
testTa.seeCourseList();
testTa.seeCourseList(courseList);
break;
case "ADD SCHEDULE":
......@@ -69,9 +83,9 @@ public class Main {
String day = sc.nextLine().toLowerCase();
System.out.println("Schedule name: ");
String name = sc.nextLine();
System.out.println("Add startTime 'XX:XX'. Example, '08:00': ");
System.out.println("Add start time 'XX:XX'. Example, '08:00': ");
String startTime = sc.nextLine();
System.out.println("Add startTime 'XX:XX'. Example, '09:40': ");
System.out.println("Add end time 'XX:XX'. Example, '09:40': ");
String endTime = sc.nextLine();
testTa.setSchedule(day, name, startTime, endTime);
......@@ -94,7 +108,7 @@ public class Main {
break;
case "COURSELIST":
testAdmin.seeCourseList();
testAdmin.seeCourseList(courseList);
break;
case "USERLIST":
......@@ -110,7 +124,18 @@ public class Main {
String professor = sc.nextLine();
System.out.println("Choose SKS: ");
int sks = Integer.valueOf(sc.nextLine());
new Course(name, courseId, professor, sks);
new Course(name, courseId, professor, sks, courseList);
// Store courselist test
try {
FileOutputStream fos = new FileOutputStream("src/softeng/g4/xyz.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(courseList);
} catch (Exception ex) {
System.out.println("Exception is caught");
}
break;
case "ASSIGN TA":
......@@ -141,17 +166,9 @@ public class Main {
public static void checkLogin(String q) {
switch (q) {
case "S":
introStudent();
break;
case "T":
introTA();
break;
case "A":
introAdmin();
break;
case "S" -> introStudent();
case "T" -> introTA();
case "A" -> introAdmin();
}
}
......@@ -190,4 +207,34 @@ public class Main {
}
public static CourseList openCourseList() {
// Deserialize courseList test
try
{
// Reading the object from a file
FileInputStream file = new FileInputStream("src/softeng/g4/xyz.txt");
ObjectInputStream in = new ObjectInputStream(file);
// Method for deserialization of object
CourseList courseList = (CourseList) in.readObject();
in.close();
file.close();
return courseList;
}
catch(IOException ex)
{
System.out.println("IOException is caught");
}
catch(ClassNotFoundException ex)
{
System.out.println("ClassNotFoundException is caught");
}
return null;
}
}
package softeng.g4;
package softeng.g4.course;
import softeng.g4.user.Student;
import softeng.g4.user.TeachingAssistant;
import java.io.Serializable;
import java.util.ArrayList;
public class Course {
public class Course implements Serializable {
private String name;
private String courseId;
private ArrayList<Student> students;
......@@ -15,15 +16,14 @@ public class Course {
private boolean adminPermission;
// Constructor
public Course(String name, String courseId, String professor, int sks) {
public Course(String name, String courseId, String professor, int sks, CourseList courseList) {
this.name = name;
this.courseId = courseId;
this.professor = professor;
this.sks = sks;
this.adminPermission = false;
// Register new course to courseList
CourseList.courseList.add(this);
courseList.courseList.add(this);
}
// Assign TA to the course
......
package softeng.g4;
package softeng.g4.course;
import java.io.Serializable;
import java.util.ArrayList;
public class CourseList {
public static ArrayList<Course> courseList = new ArrayList<Course>();
public class CourseList implements Serializable {
public ArrayList<Course> courseList = new ArrayList<Course>();
public static void showCourseList() {
public void showCourseList() {
for (Course course : courseList) {
System.out.println(course);
}
......
package softeng.g4.user;
import softeng.g4.Course;
import softeng.g4.CourseList;
import softeng.g4.appointment.Appointment;
import java.util.ArrayList;
import softeng.g4.course.Course;
import softeng.g4.course.CourseList;
public class Admin extends User {
private String username;
......@@ -28,13 +25,13 @@ public class Admin extends User {
}
// Create course
public void createCourse(String name, String courseId, String professor, int sks) {
new Course(name, courseId, professor, sks);
public void createCourse(String name, String courseId, String professor, int sks, CourseList courseList) {
new Course(name, courseId, professor, sks, courseList);
}
// See all courses
public void seeCourseList() {
CourseList.showCourseList();
public void seeCourseList(CourseList courseList) {
courseList.showCourseList();
}
public void seeAppointment() {}
......
package softeng.g4.user;
import softeng.g4.CourseList;
import softeng.g4.course.CourseList;
import softeng.g4.calendar.Calendar;
import softeng.g4.calendar.Schedule;
......@@ -23,8 +23,8 @@ public class TeachingAssistant extends UserStudent {
}
// See all courses
public void seeCourseList() {
CourseList.showCourseList();
public void seeCourseList(CourseList courseList) {
courseList.showCourseList();
}
// Set schedule on certain day
......
package softeng.g4.user;
import softeng.g4.Course;
public abstract class UserStudent extends User{
private long npm;
......
Markdown is supported
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