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
9 changes: 9 additions & 0 deletions .idea/4156-Miniproject-2024-Students-Java.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .zshrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export PATH=$PATH:/Users/wilson/apache-maven-3.9.5/bin/
Binary file added IndividualProject/data.txt
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import java.io.*;

/**
* Represents a course within a department within an educational institution.
* This class stores information about the course, including its instructor's name,
* course location, timeslot, capacity and number of enrolled students.
*/
public class Course implements Serializable {

/**
Expand All @@ -17,37 +22,43 @@ 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) {
enrolledStudentCount++;
return true;
}
return false;
}

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


public String getCourseLocation() {
return this.instructorName;
return this.courseLocation;
}


public String getInstructorName() {
return this.courseLocation;
return this.instructorName;
}


Expand All @@ -57,7 +68,8 @@ public String getCourseTimeSlot() {


public String toString() {
return "\nInstructor: " + instructorName + "; Location: " + courseLocation + "; Time: " + courseTimeSlot;
return "\nInstructor: " + instructorName + "; Location: "
+ courseLocation + "; Time: " + courseTimeSlot;
}


Expand All @@ -77,12 +89,17 @@ public void reassignTime(String newTime) {


public void setEnrolledStudentCount(int count) {
this.enrolledStudentCount = count;
if (count > enrollmentCapacity) {
enrolledStudentCount = enrollmentCapacity;
}
else{
enrolledStudentCount = count;
}
}


public boolean isCourseFull() {
return enrollmentCapacity > enrolledStudentCount;
return !(enrollmentCapacity > enrolledStudentCount);
}

@Serial
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Department(String deptCode, HashMap<String, Course> courses, String depar
* @return The number of majors.
*/
public int getNumberOfMajors() {
return -this.numberOfMajors;
return numberOfMajors;
}

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

/**
Expand All @@ -51,7 +51,7 @@ public String getDepartmentChair() {
* @return A HashMap containing courses offered by the department.
*/
public HashMap<String, Course> getCourseSelection() {
return this.courses;
return courses;
}

/**
Expand All @@ -65,7 +65,9 @@ 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--;
}
}

/**
Expand Down Expand Up @@ -100,13 +102,14 @@ public void createCourse(String courseId, String instructorName, String courseLo
*/
public String toString() {
StringBuilder result = new StringBuilder();
result.append("Department: ").append(deptCode).append("\n")
.append("courses offered: ").append("\n");
for (Map.Entry<String, Course> entry : courses.entrySet()) {
String key = entry.getKey();
Course value = entry.getValue();
result.append(deptCode).append(" ").append(key).append(": ").append(value.toString())
.append("\n");
result.append(key).append(": ").append(value.toString()).append("\n");
}
return "result.toString()";
return result.toString().substring(0,result.length()-1);
}

@Serial
Expand Down
Loading