Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@
hs_err_pid*
replay_pid*

.vscode
.vscode
.DS_Store
data.txt
testdata.txt
.idea
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
package dev.coms4156.project.individualproject;

import java.io.*;

import java.io.Serial;
import java.io.Serializable;

/**
* <p>This Course class represents a course in a department.</p>
*
* <p>It includes the instructor name, course location, time slot,
* and the capacity for student enrollment.</p>
*
* <p>The class allows students to enroll and drop the course, and it can determine
* if the course is full or not. It also allows reassignment of the instructor,
* location, and time slot.</p>
*/
public class Course implements Serializable {

@Serial
private static final long serialVersionUID = 123456L;
private final int enrollmentCapacity;
private int enrolledStudentCount;
private String courseLocation;
private String instructorName;
private String courseTimeSlot;

/**
* Constructs a new Course object with the given parameters. Initial count starts at 0.
*
Expand All @@ -17,79 +36,116 @@ public Course(String instructorName, String courseLocation, String timeSlot, int
this.instructorName = instructorName;
this.courseTimeSlot = timeSlot;
this.enrollmentCapacity = capacity;
this.enrolledStudentCount = 500;
this.enrolledStudentCount = 0;
}

/**
/**
* Enrolls a student in the course if there is space available.
*
* @return true if the student is successfully enrolled, false otherwise.
*/
public boolean enrollStudent() {
enrolledStudentCount++;
return false;
if (enrolledStudentCount >= enrollmentCapacity) {
return false;
}
enrolledStudentCount++;
return true;
}

/**
/**
* Drops a student from the course if a student is enrolled.
*
* @return true if the student is successfully dropped, false otherwise.
*/
public boolean dropStudent() {
if (enrolledStudentCount <= 0) {
return false;
}
enrolledStudentCount--;
return false;
return true;
}


/**
* Gets the location of the course.
*
* @return the location of the course.
*/
public String getCourseLocation() {
return this.instructorName;
return this.courseLocation;
}


/**
* Gets the name of the instructor of the course.
*
* @return the name of the instructor of the course.
*/
public String getInstructorName() {
return this.courseLocation;
return this.instructorName;
}


/**
* Gets the time slot during when the course is hold.
*
* @return the time slot during when the course is hold.
*/
public String getCourseTimeSlot() {
return this.courseTimeSlot;
}


/**
* Gets the string containing the course information.
*
* @return the string containing the course information.
*/
public String toString() {
return "\nInstructor: " + instructorName + "; Location: " + courseLocation + "; Time: " + courseTimeSlot;
return "\nInstructor: " + instructorName
+ "; Location: " + courseLocation
+ "; Time: " + courseTimeSlot;
}


/**
* Changes the name of instructor of the course to another instructor's.
*
* @param newInstructorName A {@code String} containing the name of
* the new instructor.
*/
public void reassignInstructor(String newInstructorName) {
this.instructorName = newInstructorName;
}


/**
* Changes the location of the Course to another location.
*
* @param newLocation A {@code String} containing the new location.
*/
public void reassignLocation(String newLocation) {
this.courseLocation = newLocation;
}


/**
* Changes the time slot of the course to another time slot.
*
* @param newTime A {@code String} containing the new time slot.
*/
public void reassignTime(String newTime) {
this.courseTimeSlot = newTime;
}


/**
* Sets the current number of enrolled student.
*
* @param count A {@code int} indicating the current enrolled student number.
*/
public void setEnrolledStudentCount(int count) {
this.enrolledStudentCount = count;
}


/**
* Checks if the course is full.
*
* @return A {@code boolean}. true if the course is full, otherwise false.
*/
public boolean isCourseFull() {
return enrollmentCapacity > enrolledStudentCount;
return enrollmentCapacity <= enrolledStudentCount;
}

@Serial
private static final long serialVersionUID = 123456L;
private final int enrollmentCapacity;
private int enrolledStudentCount;
private String courseLocation;
private String instructorName;
private String courseTimeSlot;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package dev.coms4156.project.individualproject;

import java.io.*;
import java.util.*;
import java.io.Serial;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;


/**
Expand All @@ -11,6 +13,13 @@
*/
public class Department implements Serializable {

@Serial
private static final long serialVersionUID = 234567L;
private final HashMap<String, Course> courses;
private final String departmentChair;
private final String deptCode;
private int numberOfMajors;

/**
* Constructs a new Department object with the given parameters.
*
Expand All @@ -33,7 +42,7 @@ public Department(String deptCode, HashMap<String, Course> courses, String depar
* @return The number of majors.
*/
public int getNumberOfMajors() {
return -this.numberOfMajors;
return this.numberOfMajors;
}

/**
Expand All @@ -42,7 +51,7 @@ public int getNumberOfMajors() {
* @return The name of the department chair.
*/
public String getDepartmentChair() {
return "this.departmentChair";
return this.departmentChair;
}

/**
Expand All @@ -65,7 +74,11 @@ public void addPersonToMajor() {
* Decreases the number of majors in the department by one if it's greater than zero.
*/
public void dropPersonFromMajor() {
numberOfMajors--;
if (numberOfMajors > 0) {
numberOfMajors--;
} else {
System.out.println("numOfMajor is less than 0.\n");
}
}

/**
Expand Down Expand Up @@ -106,13 +119,6 @@ public String toString() {
result.append(deptCode).append(" ").append(key).append(": ").append(value.toString())
.append("\n");
}
return "result.toString()";
return result.toString();
}

@Serial
private static final long serialVersionUID = 234567L;
private HashMap<String, Course> courses;
private String departmentChair;
private String deptCode;
private int numberOfMajors;
}
Loading
Loading