diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..97de1db --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.gitignore b/.gitignore index 85e7c1d..0a7aeb7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,9 @@ /.idea/ +.vs/* +/bin/ +./out/ +.project +.classpath +/doc/ +/obj/ +/data/ diff --git a/.project b/.project new file mode 100644 index 0000000..1f9ff0d --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + Academia-Planner + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + + + 1678385537235 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/README.md b/README.md index 59f738c..32f3ea3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,33 @@ # Academia-Planner The system we are going to build is a course registration system. +## Software Patterns +- **Singleton** +Classes: Database +- **Proxy** (enrollments) +Classes: EnrollmentProxy +- **Builder** (enrollments) +Classes: EnrollmentBuilder +- **Factory method** (department) +Interface: Department, DepartmentFactory Classes: CSDepartment(Factory), SWEDepartment(Factory), ECEDepartment(Factory) +- **Adaptor** (record, recordAdaptor) +Classes: Record, RecordAdaptor +- **Iterator** (students, courses) +Interface: Iterator, Classes: StudentIterator, CourseIterator +- **Composite** (enrollment, transcript) +Interface: Registration, Classes: Transcript +## Result +Demo: Example to create a student's transcript +``` +CS1073 Java I A 16.0 +Transcript of John Doe(ID:3333333) +Java I 4 90.0 +Java II 4 70.0 +Software Design Patterns and Architecture 4 85.0 +Average Percentage: 81.66666666666667 + +Student: John Doe(3333333), Business, Fredericton +Course[code='CS1073', name='Java I'] + +Process finished with exit code 0 +``` diff --git a/data/README.md b/data/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/doc/demo.txt b/doc/demo.txt deleted file mode 100644 index 8b13789..0000000 --- a/doc/demo.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/main/src/Controller/CourseIterator.java b/main/src/Controller/CourseIterator.java new file mode 100644 index 0000000..042fac6 --- /dev/null +++ b/main/src/Controller/CourseIterator.java @@ -0,0 +1,32 @@ +package Controller; + +import java.util.ArrayList; +import java.util.HashSet; +import Model.Course; +public class CourseIterator implements Iterator{ + private int currentPosition = 0; + private HashSet courseSet; + private ArrayList courseList; + + public CourseIterator(HashSet set) { + courseSet = set; + courseList = new ArrayList<>(courseSet); + } + + public Course getNext(){ + if(!hasNext()) { + return null; + } + Course student = courseList.get(currentPosition); + currentPosition++; + return student; + } + + public boolean hasNext() { + return currentPosition < courseList.size(); + } + + public void reset() { + currentPosition = 0; + } +} diff --git a/main/src/Controller/DepartmentFactory.java b/main/src/Controller/DepartmentFactory.java new file mode 100644 index 0000000..1d63c9c --- /dev/null +++ b/main/src/Controller/DepartmentFactory.java @@ -0,0 +1,21 @@ +package Controller; + +import Model.CSDepartment; +import Model.Department; +import Model.ECEDepartment; +import Model.SWEDepartment; + +public class DepartmentFactory { + public static Department createDepartment(String departmentType) { + if (departmentType.equalsIgnoreCase("CS")) { + return new CSDepartment(); + } else if (departmentType.equalsIgnoreCase("SWE")) { + return new SWEDepartment(); + } else if( departmentType.equalsIgnoreCase("ECE")){ + return new ECEDepartment(); + } + else { + throw new IllegalArgumentException("Invalid department type: " + departmentType); + } + } +} diff --git a/main/src/Controller/Enrol.java b/main/src/Controller/Enrol.java deleted file mode 100644 index d50f124..0000000 --- a/main/src/Controller/Enrol.java +++ /dev/null @@ -1,19 +0,0 @@ -package Controller; - -import Model.Course; -import Model.Enrollment; -import Model.Student; - -import java.util.HashSet; - -public class Enrol { - - public HashSet getStudentList(){ - return null; - } - - public Enrollment createEnrollment(Student student, Course course){ - return null; - } - -} diff --git a/main/src/Controller/EnrollmentBuilder.java b/main/src/Controller/EnrollmentBuilder.java new file mode 100644 index 0000000..0122edf --- /dev/null +++ b/main/src/Controller/EnrollmentBuilder.java @@ -0,0 +1,58 @@ +package Controller; + +import java.util.Date; + +import Model.Course; +import Model.Enrollment; +import Model.Student; +public class EnrollmentBuilder{ + private int id; + private Student student; + private Course course; + private Date termStart; + private Date termEnd; + private double grade; + private String status; + private Enrollment e; + public EnrollmentBuilder(){} + + public EnrollmentBuilder setId(int id){ + this.id=id; + return this; + } + + public EnrollmentBuilder setStudent(Student student){ + this.student=student; + return this; + } + + public EnrollmentBuilder setCourse(Course course){ + this.course=course; + return this; + } + + public EnrollmentBuilder setTermStart(Date termStart){ + this.termStart=termStart; + return this; + } + + public EnrollmentBuilder setTermEnd(Date termEnd){ + this.termEnd=termEnd; + return this; + } + + public EnrollmentBuilder setGrade(double grade){ + this.grade=grade; + return this; + } + + public EnrollmentBuilder setStatus(String status){ + this.status=status; + return this; + } + + public Enrollment build(){ + e = new Enrollment(id,student,course,termStart,termEnd,grade,status); + return e; + } +} diff --git a/main/src/Controller/EnrollmentProxy.java b/main/src/Controller/EnrollmentProxy.java new file mode 100644 index 0000000..b9c1a75 --- /dev/null +++ b/main/src/Controller/EnrollmentProxy.java @@ -0,0 +1,36 @@ +package Controller; + +import Model.Enrollment; + +import java.util.Scanner; + +public class EnrollmentProxy extends Enrollment { + private final String password; + private Enrollment enrollment; + + public EnrollmentProxy(String password) { + this.password = password; + } + + private void authenticate(String input) { +// Scanner scanner = new Scanner(System.in); +// System.out.println("Please enter password:"); +// String input = scanner.nextLine(); + + if (!input.equals(password)) { +// scanner.close(); + throw new SecurityException("Incorrect password"); + } + if (enrollment == null) { + enrollment = new Enrollment(); + } +// scanner.close(); + } + public void editGrade(String inputPassword, Enrollment enrollment, Double newGrade) { + authenticate(inputPassword); + enrollment.setGrade(newGrade); + + } + + +} \ No newline at end of file diff --git a/main/src/Controller/Init.java b/main/src/Controller/Init.java deleted file mode 100644 index e90c0be..0000000 --- a/main/src/Controller/Init.java +++ /dev/null @@ -1,20 +0,0 @@ -package Controller; - -import Model.Course; -import Model.Student; - -public class Init { - public void main(String args[]) { - Student s1 = new Student(3650173, "Hannah Day", "Fredericton", "Engineering"); - Student s2 = new Student(3470952, "John Doe", "Fredericton", "Business"); - Student s3 = new Student(3456798, "Jane Doe", "Saint John", "Computer Science"); - Student s4 = new Student(3579231, "Camila Paez", "Fredericton", "Engineering"); - - String s = "This course introduces concepts of software design patterns and architecture."; - Course c1 = new Course("SWE4403", "FR01A", 4, "Software Design Patterns and Architecture", s, "SWE"); - Course c2 = new Course("CS1073", "FR01A", 4, "Java I", "Introduction to Java I", "CS"); - Course c3 = new Course("CS1083", "FR01A", 4, "Java II", "Introduction to Java II", "CS"); - Course c4 = new Course("ECE4403", "FR01A", 4, "Software Design Fundamentals", - "This course introduces concepts of software design patterns and architecture.", "ECE"); - } -} diff --git a/main/src/Controller/Iterator.java b/main/src/Controller/Iterator.java new file mode 100644 index 0000000..678e3a0 --- /dev/null +++ b/main/src/Controller/Iterator.java @@ -0,0 +1,8 @@ +package Controller; + +public interface Iterator { + public T getNext(); + public boolean hasNext(); + public void reset(); +} + diff --git a/main/src/Controller/RecordAdapter.java b/main/src/Controller/RecordAdapter.java new file mode 100644 index 0000000..4df59b1 --- /dev/null +++ b/main/src/Controller/RecordAdapter.java @@ -0,0 +1,91 @@ +package Controller; + +import Model.Course; +import Model.Enrollment; +import Model.Record; + +import java.util.HashMap; + +public class RecordAdapter implements Record { + private Enrollment enrollment; + private Course course; + HashMap ptScheme; + private int creditHours; + + private String letterGrade; + private double points; + + private String status; + + public RecordAdapter(Enrollment enrollment) { + this.enrollment=enrollment; + this.course= enrollment.getCourse(); + this.creditHours = course.getCreditHours(); + ptScheme= new HashMap(); + + setPointScheme(); + updateLG(); + + calculatePoints(); + + } + + private void setPointScheme() { + ptScheme.put("A+", 4.3); + ptScheme.put("A", 4.0); + ptScheme.put("A-", 3.7); + ptScheme.put("B+", 3.3); + ptScheme.put("B", 3.0); + ptScheme.put("B-", 2.7); + ptScheme.put("C+", 2.3); + ptScheme.put("C", 2.0); + ptScheme.put("C-", 1.7); + } + + private void updateLG() { + status = enrollment.getStatus(); + if (status == "WITHDRAWN") {letterGrade = "W";} + if (status == "INPROGRESS") {letterGrade = "INP";} + else { + HashMap scheme = course.getScheme(); + + double grade=enrollment.getGrade(); + for(double g: scheme.keySet()){ + + if(grade>=g){ + + letterGrade=scheme.get(grade); + + break; + } + } + } + } + + private void calculatePoints() { + for(String g: ptScheme.keySet()){ + if(letterGrade == g){ + + points=ptScheme.get(letterGrade)*creditHours; + break; + } + } + } + + + @Override + public String getCode() {return course.getCode();} + + @Override + public String getCourseName() {return course.getName();} + + + @Override + public String getLetterGrade() {return letterGrade;} + + @Override + public double getCreditHrs() {return creditHours;} + + @Override + public double getPoints() {return points;} +} diff --git a/main/src/Controller/StudentIterator.java b/main/src/Controller/StudentIterator.java new file mode 100644 index 0000000..21a7fac --- /dev/null +++ b/main/src/Controller/StudentIterator.java @@ -0,0 +1,35 @@ +package Controller; + +import java.util.ArrayList; +import java.util.HashSet; + +import Model.Student; + +public class StudentIterator implements Iterator{ + private int currentPosition = 0; + private HashSet stuSet; + private ArrayList stuList; + + public StudentIterator(HashSet set) { + stuSet = set; + stuList = new ArrayList<>(stuSet); + } + + public Student getNext(){ + if(!hasNext()) { + return null; + } + Student student = stuList.get(currentPosition); + currentPosition++; + return student; + } + + public boolean hasNext() { + return currentPosition < stuList.size(); + } + + public void reset() { + currentPosition = 0; + } +} + diff --git a/main/src/Model/CSDepartment.java b/main/src/Model/CSDepartment.java new file mode 100644 index 0000000..02795b0 --- /dev/null +++ b/main/src/Model/CSDepartment.java @@ -0,0 +1,17 @@ +package Model; + +public class CSDepartment implements Department { + private final String departmentName = "Computer Science Department"; + private final String departmentCode = "CS"; + + public CSDepartment(){} + @Override + public String getDepartmentName() { + return departmentName; + } + + @Override + public String getDepartmentCode() { + return departmentCode; + } +} diff --git a/main/src/Model/CSDepartmentFactory.java b/main/src/Model/CSDepartmentFactory.java new file mode 100644 index 0000000..8004514 --- /dev/null +++ b/main/src/Model/CSDepartmentFactory.java @@ -0,0 +1,8 @@ +package Model; + +public class CSDepartmentFactory implements DepartmentFactory{ + @Override + public Department createDepartment() { + return new CSDepartment(); + } +} \ No newline at end of file diff --git a/main/src/Model/Course.java b/main/src/Model/Course.java index 57e3639..0c74d85 100644 --- a/main/src/Model/Course.java +++ b/main/src/Model/Course.java @@ -1,43 +1,98 @@ package Model; +import java.util.ArrayList; +import java.util.HashMap; + public class Course { - private String code; - private String section; - private int creditHours; - private String name; - private String description; - private String courseType; - //Techinically we could have a list of class times in some sort of structure but we might not wanna mess with that at this time. - - public Course(){ - } - - public Course(String code, String section, int creditHours, String name, String description, String courseType){ - this.code=code; - this.section=section; - this.creditHours=creditHours; - this.name=name; - this.description=description; - this.courseType=courseType; - } - - public String getCode(){ return code; } - public void setCode(String code){ this.code=code; } - - public String getSection(){ return section; } - public void setSection(String section){ this.section=section; } - - public int getCreditHours(){ return creditHours; } - public void setCreditHours(int creditHours){ this.creditHours=creditHours; } - - public String getName(){ return name; } - public void setName(String name){ this.name=name; } - - public String getDescription(){ return description; } - public void setDescription(String description){ this.description=description; } - - public String getCourseType(){ return courseType; } - public void setCourseType(String courseType){ this.courseType=courseType;} - - //Equals method needed? -} \ No newline at end of file + private String code; + private String section; + private int creditHours; + private String name; + private String description; + private Department department; + private ArrayList prerequisites; + private HashMap scheme; + //Techinically we could have a list of class times in some sort of structure but we might not wanna mess with that at this time. + + public Course(){ + prerequisites=new ArrayList(); + } + public Course(String code, String section, int creditHours, String name, String description, Department department){ + this.code=code; + this.section=section; + this.creditHours=creditHours; + this.name=name; + this.description=description; + this.department=department; + this.prerequisites=new ArrayList(); + //Default scheme + this.scheme = new HashMap(); + scheme.put(95.0, "A+"); + scheme.put(90.0, "A"); + scheme.put(85.0, "A-"); + scheme.put(80.0, "B+"); + scheme.put(75.0, "B"); + scheme.put(70.0, "B-"); + scheme.put(65.0, "C+"); + scheme.put(60.0, "C"); + scheme.put(55.0, "C-"); + scheme.put(50.0, "D"); + scheme.put(0.0,"F"); + } + + public Course(String code, String section, int creditHours, String name, String description, Department department, ArrayList prerequisites){ + this.code=code; + this.section=section; + this.creditHours=creditHours; + this.name=name; + this.description=description; + this.department=department; + this.prerequisites=prerequisites; + //Default scheme + scheme.put(95.0, "A+"); + scheme.put(90.0, "A"); + scheme.put(85.0, "A-"); + scheme.put(80.0, "B+"); + scheme.put(75.0, "B"); + scheme.put(70.0, "B-"); + scheme.put(65.0, "C+"); + scheme.put(60.0, "C"); + scheme.put(55.0, "C-"); + scheme.put(50.0, "D"); + scheme.put(0.0,"F"); + } + + public String getCode(){ return code; } + public void setCode(String code){ this.code=code; } + + public String getSection(){ return section; } + public void setSection(String section){ this.section=section; } + + public int getCreditHours(){ return creditHours; } + public void setCreditHours(int creditHours){ this.creditHours=creditHours; } + + public String getName(){ return name; } + public void setName(String name){ this.name=name; } + + public String getDescription(){ return description; } + public void setDescription(String description){ this.description=description; } + + public Department getDepartment(){ return department; } + public void setDepartment(Department department){ this.department=department;} + + public HashMap getScheme(){ return scheme;} + public void setScheme(HashMap scheme) {this.scheme=scheme;} + + public ArrayList getPreRequisites(){ return prerequisites; } + public void setPrerequisites(ArrayList prerequisites){ this.prerequisites=prerequisites; } + //Equals method needed? + + + @Override + public String toString() { + return "Course[" + + "code='" + code + '\'' + + ", name='" + name + '\'' + + ']'; + } +} diff --git a/main/src/Model/Database.java b/main/src/Model/Database.java index f253e0d..f9ea815 100644 --- a/main/src/Model/Database.java +++ b/main/src/Model/Database.java @@ -1,16 +1,21 @@ package Model; import java.util.*; +import Controller.*; +import Controller.Iterator; public class Database{ private static Database instance; - private HashMap students; - private HashMap courses; + private HashSet students; + private HashSet courses; //We could use this as a 'logging' feature or something. The history of the session's actions. - private HashMap enrollments; + private HashSet enrollments; + //Transcript probably good here too private Database(){ - this.students=new HashMap(); + this.students=new HashSet<>(); + this.courses=new HashSet<>(); + this.enrollments=new HashSet<>(); } public static Database getDB(){ @@ -22,25 +27,48 @@ public static Database getDB(){ } public Student getStudent(int id){ - return students.get(id); + Iterator itr = new StudentIterator(students); + while(itr.hasNext()) { + Student val=itr.getNext(); + if(val.getStudentID()==id){ + return val; + } + } + return null; + } + + public void addStudent(Student s){ + students.add(s); } //Could possibly return students.values() for a collection of Students if we want to observe all students instead of the map directly - public HashMap getStudentMap(){ + public HashSet getStudentMap(){ return students; } //Same thing with courses. - public HashMap getCourseMap(){ + public HashSet getCourseMap(){ return courses; } public Course getCourse(String courseCode){ - return courses.get(courseCode); + Iterator itr=new CourseIterator(courses); + while(itr.hasNext()) { + Course val=itr.getNext(); + if(val.getCode()==courseCode){ + return val; + } + } + return null; + } + + public void addCourse(Course c){ + courses.add(c); } //Same with enrollments - public HashMap getEnrollments(){ + public HashSet getEnrollments(){ return enrollments; } + } diff --git a/main/src/Model/Department.java b/main/src/Model/Department.java new file mode 100644 index 0000000..69c251e --- /dev/null +++ b/main/src/Model/Department.java @@ -0,0 +1,6 @@ +package Model; + +public interface Department { + String getDepartmentName(); + String getDepartmentCode(); +} diff --git a/main/src/Model/DepartmentFactory.java b/main/src/Model/DepartmentFactory.java new file mode 100644 index 0000000..5bebe28 --- /dev/null +++ b/main/src/Model/DepartmentFactory.java @@ -0,0 +1,7 @@ +package Model; + + +public interface DepartmentFactory { + + Department createDepartment(); +} \ No newline at end of file diff --git a/main/src/Model/ECEDepartment.java b/main/src/Model/ECEDepartment.java new file mode 100644 index 0000000..700dd23 --- /dev/null +++ b/main/src/Model/ECEDepartment.java @@ -0,0 +1,17 @@ +package Model; + +public class ECEDepartment implements Department{ + private final String departmentName = "Electrical Engineering Department"; + private final String departmentCode = "ECE"; + + public ECEDepartment(){} + @Override + public String getDepartmentName() { + return departmentName; + } + + @Override + public String getDepartmentCode() { + return departmentCode; + } +} \ No newline at end of file diff --git a/main/src/Model/ECEDepartmentFactory.java b/main/src/Model/ECEDepartmentFactory.java new file mode 100644 index 0000000..34cf47d --- /dev/null +++ b/main/src/Model/ECEDepartmentFactory.java @@ -0,0 +1,8 @@ +package Model; + +public class ECEDepartmentFactory implements DepartmentFactory{ + @Override + public Department createDepartment() { + return new ECEDepartment(); + } +} \ No newline at end of file diff --git a/main/src/Model/Enrollment.java b/main/src/Model/Enrollment.java index a5ae64c..a695e7c 100644 --- a/main/src/Model/Enrollment.java +++ b/main/src/Model/Enrollment.java @@ -1,21 +1,29 @@ package Model; import java.util.*; -public class Enrollment{ +public class Enrollment implements Registration{ private int id; private Student student; private Course course; private Date termStart; private Date termEnd; private double grade; - //Take from a course grading scheme or a default grading? - private String letterGrade; - //Should probably be an enum PASSED,FAILED,WITHDRAWN,INPROGRESS + //Should probably be an enum WITHDRAWN,INPROGRESS private String status; public Enrollment(){ } + public Enrollment(int id, Student student, Course course, + Date termStart, Date termEnd, double grade, String status){ + this.id=id; + this.student=student; + this.course=course; + this.termStart=termStart; + this.termEnd=termEnd; + this.grade=grade; + this.status=status; + } public int getID(){ return id;} //Should probably not be modified public void setID(int id){ this.id=id; } @@ -38,28 +46,6 @@ public Enrollment(){ public double getGrade(){ return grade; } public void setGrade(double grade){ this.grade=grade; } - public String getLetterGrade(){ return letterGrade; } - public void updateLetterGrade() { - HashMap scheme = new HashMap<>(); - scheme.put(95.0, "A+"); - scheme.put(90.0, "A"); - scheme.put(85.0, "A-"); - scheme.put(80.0, "B+"); - scheme.put(75.0, "B"); - scheme.put(70.0, "B-"); - scheme.put(65.0, "C+"); - scheme.put(60.0, "C"); - scheme.put(55.0, "C-"); - scheme.put(50.0, "D"); - scheme.put(0.0,"F"); - double grade=this.grade; - for(double g: scheme.keySet()){ - if(grade>=g){ - letterGrade=scheme.get(g); - } - } - } - public String getStatus(){ return status; } public void setStatus(String status){ this.status=status; } } \ No newline at end of file diff --git a/main/src/Model/Record.java b/main/src/Model/Record.java new file mode 100644 index 0000000..0be0c85 --- /dev/null +++ b/main/src/Model/Record.java @@ -0,0 +1,9 @@ +package Model; + +public interface Record { + public String getCode(); + public String getCourseName(); + public String getLetterGrade(); + public double getCreditHrs(); + public double getPoints(); +} diff --git a/main/src/Model/Registration.java b/main/src/Model/Registration.java new file mode 100644 index 0000000..8e25e4c --- /dev/null +++ b/main/src/Model/Registration.java @@ -0,0 +1,6 @@ +package Model; + +public interface Registration +{ + public double getGrade(); +} diff --git a/main/src/Model/SWEDepartment.java b/main/src/Model/SWEDepartment.java new file mode 100644 index 0000000..7e01d8d --- /dev/null +++ b/main/src/Model/SWEDepartment.java @@ -0,0 +1,17 @@ +package Model; + +public class SWEDepartment implements Department { + private final String departmentName = "Software Engineering Department"; + private final String departmentCode = "SWE"; + + public SWEDepartment(){} + @Override + public String getDepartmentName() { + return departmentName; + } + + @Override + public String getDepartmentCode() { + return departmentCode; + } +} diff --git a/main/src/Model/SWEDepartmentFactory.java b/main/src/Model/SWEDepartmentFactory.java new file mode 100644 index 0000000..7fae918 --- /dev/null +++ b/main/src/Model/SWEDepartmentFactory.java @@ -0,0 +1,8 @@ +package Model; + +public class SWEDepartmentFactory implements DepartmentFactory{ + @Override + public Department createDepartment() { + return new SWEDepartment(); + } +} \ No newline at end of file diff --git a/main/src/Model/Student.java b/main/src/Model/Student.java index 61284b7..4003cfb 100644 --- a/main/src/Model/Student.java +++ b/main/src/Model/Student.java @@ -29,4 +29,9 @@ public Student(int studentID, String name, String campus, String program){ public String getProgram(){ return program; } public void setProgram(String program){ this.program=program; } //Equals method needed? + + @Override + public String toString() { + return "Student: " + this.name + "(" + studentID + "), " + program + ", " + campus; + } } diff --git a/main/src/Model/Transcript.java b/main/src/Model/Transcript.java new file mode 100644 index 0000000..2babbf4 --- /dev/null +++ b/main/src/Model/Transcript.java @@ -0,0 +1,46 @@ +package Model; + +import java.util.List; + +public class Transcript implements Registration +{ + Student student; + List enrollments; + + public Transcript(Student student, List enrollments) + { + this.student = student; + this.enrollments = enrollments; + } + + public void addEnrollment(Enrollment e) + { + enrollments.add(e); + } + + public double getGrade() + { + double average_percentage = 0; + for(Enrollment e: enrollments) + { + average_percentage += e.getGrade(); + } + + + return average_percentage/enrollments.size(); + } + + public String toString() + { + StringBuffer print = new StringBuffer(); + print.append("Transcript of " +student.getName()+"(ID:"+ student.getStudentID()+")"+"\n"); + + for (Enrollment e: enrollments) + { + print.append(e.getCourse().getName() + "\t" + e.getCourse().getCreditHours() + "\t" + e.getGrade()+"\n"); + } + print.append("Average Percentage: " + this.getGrade()+"\n"); + return String.valueOf(print); + } + +} diff --git a/main/src/View/CourseResgistration.java b/main/src/View/CourseResgistration.java deleted file mode 100644 index e6cd5a4..0000000 --- a/main/src/View/CourseResgistration.java +++ /dev/null @@ -1,49 +0,0 @@ -package View; - -import javafx.application.Application; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import javafx.geometry.Insets; -import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.scene.control.ListView; -import javafx.scene.layout.VBox; -import javafx.stage.Stage; - -public class CourseRegistration extends Application { - private ObservableList courses = FXCollections.observableArrayList(); - private ListView coursesListView = new ListView<>(courses); - - @Override - public void start(Stage primaryStage) { - // Load the available course list from the backend - loadCourses(); - - Button registerButton = new Button("Register"); - registerButton.setOnAction(e -> registerSelectedCourses()); - - VBox root = new VBox(10); - root.setPadding(new Insets(10)); - root.getChildren().addAll(coursesListView, registerButton); - - Scene scene = new Scene(root, 400, 400); - primaryStage.setScene(scene); - primaryStage.setTitle("Course Registration"); - primaryStage.show(); - } - - private void loadCourses() { - // TODO: Load the available course list from the backend - courses.addAll("SWE4403", "SWE4203, "SWE4103", "CS4103"); - } - - private void registerSelectedCourses() { - // TODO: Send the registering information to the backend - System.out.println("Selected courses: " + coursesListView.getSelectionModel().getSelectedItems()); - } - - public static void main(String[] args) { - launch(args); - } -} - diff --git a/main/src/View/Demo.java b/main/src/View/Demo.java new file mode 100644 index 0000000..ca64e68 --- /dev/null +++ b/main/src/View/Demo.java @@ -0,0 +1,81 @@ +package View; + + +import Controller.EnrollmentBuilder; +import Controller.EnrollmentProxy; +import Controller.RecordAdapter; +import Model.*; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.concurrent.TimeUnit; + +public class Demo { + public static void main(String[] args) throws InterruptedException { + + // init two student + Student s1 = new Student(3333333, "John Doe", "Fredericton", "Business"); + Student s2 = new Student(4444444, "Mary Smith", "Saint John", "Computer Science"); + + // Yuzhuo Factory method + + Department csdprt = new CSDepartmentFactory().createDepartment(); + Department swedprt = new SWEDepartmentFactory().createDepartment(); + + // init three course to show different prerequsites and departments + Course c1 = new Course("CS1073", "FR01A", 4, "Java I", "Introduction to Java I", csdprt); + Course c2 = new Course("CS1083", "FR01A", 4, "Java II", "Introduction to Java II", csdprt); + Course c3 = new Course("SWE4403", "FR01A", 4, "Software Design Patterns and Architecture", "GoF software design patterns", swedprt); + + // Luc builder + EnrollmentBuilder enrollmentBuilder = new EnrollmentBuilder(); + enrollmentBuilder.setId(1); + enrollmentBuilder.setStudent(s1); + enrollmentBuilder.setCourse(c1); + enrollmentBuilder.setGrade(80.0); + enrollmentBuilder.setStatus("pass"); + enrollmentBuilder.setTermStart(new Date()); + TimeUnit.SECONDS.sleep(1); + enrollmentBuilder.setTermEnd(new Date()); + Enrollment e1 = enrollmentBuilder.build(); + // modify grades + + + // Yuzhuo proxy + EnrollmentProxy ep1 = new EnrollmentProxy("123"); + ep1.editGrade("123",e1,90.0); + + + + // Hannah decorator + RecordAdapter recordAdapter= new RecordAdapter(e1); + String record = new String(); + record+=recordAdapter.getCode()+" "+recordAdapter.getCourseName()+" "+recordAdapter.getLetterGrade()+" "+recordAdapter.getPoints(); + System.out.println(record); + + // Madison composite + Enrollment e2 = new Enrollment(1, s1, c2, new Date(), new Date(), 70, "pass"); + Enrollment e3 = new Enrollment(1, s1, c3, new Date(), new Date(), 85, "pass"); + List enrollments = new ArrayList(); + enrollments.add(e1); + enrollments.add(e2); + enrollments.add(e3); + Transcript t = new Transcript(s1,enrollments); + System.out.println(t.toString()); + + // Camila iterator + // Luc Singleton + Database db = Database.getDB(); + db.addStudent(s1); + db.addStudent(s2); + db.addCourse(c1); + db.addCourse(c2); + db.addCourse(c3); + System.out.println( db.getStudent(3333333)); + System.out.println( db.getCourse("CS1073")); + + + + } +} \ No newline at end of file diff --git a/main/src/View/Program.java b/main/src/View/Program.java new file mode 100644 index 0000000..054eb39 --- /dev/null +++ b/main/src/View/Program.java @@ -0,0 +1,152 @@ +package View; + +import Model.*; + +import java.util.*; + + + +public class Program{ + private static String prompt= + "0.) Exit Program\n"+ + "1.) Add Student\n"+ + "2.) Add Course\n"+ + "3.) Add Student to course(Enrollment)\n"+ + "4.) Generate Transcript\n"+ + "5.) Edit an enrollment\n\n"+ + "Your choice: "; + public static void main(String[] args) { + init(); + boolean quit=false; + Scanner sc=new Scanner(System.in); + while(!quit){ + System.out.print(prompt); + int input=-1; + try{ + input=sc.nextInt(); + }catch (InputMismatchException e){ + System.out.println("No number detected. Please try again."); + continue; + } + //Input is in fact a number + + switch(input){ + case 0: + quit=true;break; + case 1: + newStudent();break; + case 2: + newCourse();break; + case 3: + addStudentToCourse();break; + default: + System.out.println("No option selected. Please try again.\n"); + break; + } + } + sc.close(); + } + + private static void init(){ + Database db=Database.getDB(); + db.addStudent(new Student(3650173, "Hannah Day", "Fredericton", "Engineering")); + db.addStudent(new Student(3470952, "John Doe", "Fredericton", "Business")); + db.addStudent(new Student(3456798, "Jane Doe", "Saint John", "Computer Science")); + db.addStudent(new Student(3579231, "Camila Paez", "Fredericton", "Engineering")); + + String s = "This course introduces concepts of software design patterns and architecture."; + db.addCourse(new Course("SWE4403", "FR01A", 4, "Software Design Patterns and Architecture", s, new SWEDepartment())); + db.addCourse(new Course("CS1073", "FR01A", 4, "Java I", "Introduction to Java I", new CSDepartment())); + db.addCourse(new Course("CS1083", "FR01A", 4, "Java II", "Introduction to Java II", new CSDepartment(), new ArrayList<>(Arrays.asList("Java 1")))); + db.addCourse(new Course("ECE4403", "FR01A", 4, "Software Design Fundamentals", + "This course introduces concepts of software design patterns and architecture.", new ECEDepartment())); + } + + private static void newStudent(){ + //Do stuff + //Irl there would be validation of data and options over text input. + Scanner s=new Scanner(System.in); + //This would be auto generated + int id=-1; + while(true){ + System.out.print("Please input the Student's ID: "); + try{ + id=s.nextInt(); + }catch (InputMismatchException e){ + System.out.println("No number detected. Please try again."); + continue; + } + break; + } + //Got the ID + + System.out.print("Please input the Student's Name"); + String name=s.next(); + System.out.print("Please input the Student's Campus"); + String campus=s.next(); + System.out.print("Please input the Student's Progress"); + String program=s.next(); + s.close(); + + System.out.println("Adding new student to database."); + Database.getDB().addStudent(new Student(id,name,campus,program)); + } + + public static void newCourse(){ + Scanner s=new Scanner(System.in); + System.out.print("Please input the Course's Code"); + String code=s.next(); + System.out.print("Please input the Course's Section"); + String section=s.next(); + int hours=-1; + while(true){ + System.out.print("Please input the Course's Credit Hours"); + try{ + hours=s.nextInt(); + }catch (InputMismatchException e){ + System.out.println("No number detected. Please try again."); + continue; + } + break; + } + System.out.print("Please input the Course's Name"); + String name=s.next(); + System.out.print("Please input the Course's Description"); + String description=s.nextLine(); + System.out.print("Please input the Course's Department"); + String dep=s.next(); + Department department=createDepartment(dep); + System.out.print("Please input the Course's Prerequisites if there are any\nFormat: Course1 Course2 ..."); + String[] courses=s.nextLine().split(" "); + ArrayList courseList=new ArrayList<>(); + for(String str: courses){ + Course c=Database.getDB().getCourse(str); + if(c==null){ + System.out.println("Course "+str+" does not currently exist. Skipping target."); + }else{ + courseList.add(str); + } + } + s.close(); + System.out.println("Adding new course to Database."); + Database.getDB().addCourse(new Course(code,section,hours,name,description,department, courseList)); + + } + + private static void addStudentToCourse(){ + //TBD + } + + private static Department createDepartment(String departmentType){ + if (departmentType.equalsIgnoreCase("CS")) { + return new CSDepartmentFactory().createDepartment(); + } else if (departmentType.equalsIgnoreCase("SWE")) { + return new SWEDepartmentFactory().createDepartment(); + } else if( departmentType.equalsIgnoreCase("ECE")){ + return new ECEDepartmentFactory().createDepartment(); + } + else { + throw new IllegalArgumentException("Invalid department type: " + departmentType); + } + } +} \ No newline at end of file diff --git a/out/production/main/Controller/CourseIterator.class b/out/production/main/Controller/CourseIterator.class new file mode 100644 index 0000000..f516e54 Binary files /dev/null and b/out/production/main/Controller/CourseIterator.class differ diff --git a/out/production/main/Controller/DepartmentFactory.class b/out/production/main/Controller/DepartmentFactory.class new file mode 100644 index 0000000..8a72cc7 Binary files /dev/null and b/out/production/main/Controller/DepartmentFactory.class differ diff --git a/out/production/main/Controller/EnrollmentBuilder.class b/out/production/main/Controller/EnrollmentBuilder.class new file mode 100644 index 0000000..a82131a Binary files /dev/null and b/out/production/main/Controller/EnrollmentBuilder.class differ diff --git a/out/production/main/Controller/EnrollmentProxy.class b/out/production/main/Controller/EnrollmentProxy.class new file mode 100644 index 0000000..3d3424e Binary files /dev/null and b/out/production/main/Controller/EnrollmentProxy.class differ diff --git a/out/production/main/Controller/Iterator.class b/out/production/main/Controller/Iterator.class new file mode 100644 index 0000000..8024496 Binary files /dev/null and b/out/production/main/Controller/Iterator.class differ diff --git a/out/production/main/Controller/RecordAdapter.class b/out/production/main/Controller/RecordAdapter.class new file mode 100644 index 0000000..6ca248f Binary files /dev/null and b/out/production/main/Controller/RecordAdapter.class differ diff --git a/out/production/main/Controller/StudentIterator.class b/out/production/main/Controller/StudentIterator.class new file mode 100644 index 0000000..cac6fcc Binary files /dev/null and b/out/production/main/Controller/StudentIterator.class differ diff --git a/out/production/main/Model/CSDepartment.class b/out/production/main/Model/CSDepartment.class new file mode 100644 index 0000000..e98e9e0 Binary files /dev/null and b/out/production/main/Model/CSDepartment.class differ diff --git a/out/production/main/Model/CSDepartmentFactory.class b/out/production/main/Model/CSDepartmentFactory.class new file mode 100644 index 0000000..4c9fc90 Binary files /dev/null and b/out/production/main/Model/CSDepartmentFactory.class differ diff --git a/out/production/main/Model/Course.class b/out/production/main/Model/Course.class new file mode 100644 index 0000000..8950d06 Binary files /dev/null and b/out/production/main/Model/Course.class differ diff --git a/out/production/main/Model/Database.class b/out/production/main/Model/Database.class new file mode 100644 index 0000000..c909396 Binary files /dev/null and b/out/production/main/Model/Database.class differ diff --git a/out/production/main/Model/Department.class b/out/production/main/Model/Department.class new file mode 100644 index 0000000..4ce0017 Binary files /dev/null and b/out/production/main/Model/Department.class differ diff --git a/out/production/main/Model/DepartmentFactory.class b/out/production/main/Model/DepartmentFactory.class new file mode 100644 index 0000000..7941953 Binary files /dev/null and b/out/production/main/Model/DepartmentFactory.class differ diff --git a/out/production/main/Model/ECEDepartment.class b/out/production/main/Model/ECEDepartment.class new file mode 100644 index 0000000..3eadadd Binary files /dev/null and b/out/production/main/Model/ECEDepartment.class differ diff --git a/out/production/main/Model/ECEDepartmentFactory.class b/out/production/main/Model/ECEDepartmentFactory.class new file mode 100644 index 0000000..6f370a1 Binary files /dev/null and b/out/production/main/Model/ECEDepartmentFactory.class differ diff --git a/out/production/main/Model/Enrollment.class b/out/production/main/Model/Enrollment.class new file mode 100644 index 0000000..0746a23 Binary files /dev/null and b/out/production/main/Model/Enrollment.class differ diff --git a/out/production/main/Model/Record.class b/out/production/main/Model/Record.class new file mode 100644 index 0000000..5833da7 Binary files /dev/null and b/out/production/main/Model/Record.class differ diff --git a/out/production/main/Model/Registration.class b/out/production/main/Model/Registration.class new file mode 100644 index 0000000..f72ce3e Binary files /dev/null and b/out/production/main/Model/Registration.class differ diff --git a/out/production/main/Model/SWEDepartment.class b/out/production/main/Model/SWEDepartment.class new file mode 100644 index 0000000..8152fd1 Binary files /dev/null and b/out/production/main/Model/SWEDepartment.class differ diff --git a/out/production/main/Model/SWEDepartmentFactory.class b/out/production/main/Model/SWEDepartmentFactory.class new file mode 100644 index 0000000..15ae98d Binary files /dev/null and b/out/production/main/Model/SWEDepartmentFactory.class differ diff --git a/out/production/main/Model/Student.class b/out/production/main/Model/Student.class new file mode 100644 index 0000000..85d5150 Binary files /dev/null and b/out/production/main/Model/Student.class differ diff --git a/out/production/main/Model/Transcript.class b/out/production/main/Model/Transcript.class new file mode 100644 index 0000000..3f6c233 Binary files /dev/null and b/out/production/main/Model/Transcript.class differ diff --git a/out/production/main/View/Demo.class b/out/production/main/View/Demo.class new file mode 100644 index 0000000..10cbcd0 Binary files /dev/null and b/out/production/main/View/Demo.class differ diff --git a/out/production/main/View/Program.class b/out/production/main/View/Program.class new file mode 100644 index 0000000..4bbbf31 Binary files /dev/null and b/out/production/main/View/Program.class differ