Repository: Farouk12385/UniversitySystem
Pull request #2: edited
Author: login: Farouk12385
Created: 2025-04-21T20:32:32Z | Merged: 2025-04-21T20:32:52Z

## Summary by Sourcery

Implement course and student management methods in the university system, adding functionality to check course capacity and student status

New Features:
- Add course capacity tracking with maximum and current enrollment
- Implement method to check if a course is full
- Add method to determine if a student is a normal student

Bug Fixes:
- Fix incomplete methods for course and student management

Enhancements:
- Improve course and student tracking methods
- Add more detailed status checking for courses and students

Chores:
- Update README.md to reflect completed methods
- Add CODEOWNERS file to the project


Diff:
diff --git a/CODEOWNERS b/CODEOWNERS
new file mode 100644
index 0000000..e808fd0
--- /dev/null
+++ b/CODEOWNERS
@@ -0,0 +1,2 @@
+#Defauly code owner for files in this repo
+*@Farouk12385
diff --git a/Courses.java b/Courses.java
index 9b9d6b8..f72c7c5 100644
--- a/Courses.java
+++ b/Courses.java
@@ -2,23 +2,31 @@ public class Courses {
     
     int courseID;
     Courses nextCourse;
+    int maxCapacity; // Max amount of students that can join the course. FCDS project required 20-30 students. So I made it 30.
+    int currentEnrollment;  // To track the number of students currently enrolled in the chosen course. 
 
 public Courses() {
         this.nextCourse = null;
+        this.maxCapacity = 30;  // 30 as chosen by Dr. Doaa
+        this.currentEnrollment = 0;  // Initial value, untill a student is added later on. 
     }
 public Courses(int courseID) {
         // Initialize the courseID
         // and set nextCourse to null
         this.courseID = courseID;
         this.nextCourse = null;
+        this.maxCapacity = 30;  
+        this.currentEnrollment = 0;  
     }
 public  Courses(int courseID, Courses nextCourse) {
         // Initialize the courseID
         // and set nextCourse to the given value
         this.courseID = courseID;
         this.nextCourse = nextCourse;
+        this.maxCapacity = 30;  
+        this.currentEnrollment = 0;  
     }
-    public void addStudent(int studentID) {
+   public void addStudent(int studentID) {
         // Add a student to the course
         if (this.nextCourse == null) {
             this.nextCourse = new Courses(studentID);
@@ -26,5 +34,4 @@ public void addStudent(int studentID) {
             this.nextCourse.addStudent(studentID);
         }
     }
-
 }
diff --git a/README.md b/README.md
index 0bff577..82c4aa7 100644
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@ methods
 ----------------------------------------------------------------------------------------------------
  teams
     #1-farook-nabil-ibrahim"not exsist bec ahmed ez fezamanoooo"
-    methods
+    methods+main
         1-add student  "done"
         2-add course   "done"
         3-remode student "done"
@@ -69,15 +69,15 @@ methods
         6-get last course added"done"
         15-undo enrollment stack
     #2-zeyad-ayman-farouk-rashad(mmultiverse)
-        7-enrool student in course
+        7-enrool student in course "done" by rashad
         8-removeenrollment
-        9-list course by sstudent
+        9-list course by sstudent 
         10-list student by course
         11-sort students by id
     #3-aly amr-adham-hassouna
-    methods+
-        main
+    methods
         12-sort courses by id
-        13-if full course or not
-        14-is normal student or not
-        16-redo enrollment stack
\ No newline at end of file
+        13-if full course or not "done" by aly
+        14-is normal student or not"done" by aly
+        16-redo enrollment stack
+        test
diff --git a/Uni.java b/Uni.java
index 3ccf808..4731323 100644
--- a/Uni.java
+++ b/Uni.java
@@ -1,55 +1,5 @@
 
 import java.util.Scanner;
-/*
-    teams
-    1-farook-nabil-ibrahim"not exsist bec ahmed ez fezamanoooo"
-    methods
-        1-add student  "done"
-        2-add course   "done"
-        3-remode student "done"
-        4-remove course "done"
-        5-get last student added"done"
-        6-get last course added"done"
-        15-undo enrollment stack
-    2-zeyad-ayman-farouk-rashad(mmultiverse)
-        7-enrool student in course
-        8-removeenrollment
-        9-list course by sstudent
-        10-list student by course
-        11-sort students by id
-    3-aly amr-adham-hassouna
-    methods+
-        main
-        12-sort courses by id
-        13-if full course or not
-        14-is normal student or not
-        16-redo enrollment stack
-        
-    */
-    
-    //---------------------------------------------------------------------------
-    
-    /* method to implements
-    1- add student=>add new student to the list of students linked list
-    2- add course=>add new course to the list of courses linked list
-    3- remove student=>remove student from the list of students linked list
-    4- remove course=>remove course from the list of courses linked list
-    5- get last student added=>return the id of the last student added to the list of students
-    6- get last course added=>return the id of the last course added to the list of courses
-    7- enroll student in course=>enroll student in the course update the both lists
-    8- remove enrollment=>remove the enrollment of the student from the course
-    9- list course by student=>list all the courses that the student is enrolled in
-    10- list student by course=>list all the students that are enrolled in the course
-    11- sort students by id=>sort the list of students by id
-    12- sort courses by id=>sort the list of courses by id
-    13- if full course or not=>check if the course is full or not
-    14- is normal student or not=>check if the student is normal or not
-    15-undo enrollment=>undo the enrollment of the student from the course "stack"
-    16- redo enrollment=>redo the enrollment of the student in the course "stack"
-
-    to make some funny games "method to flex"
-     */
-    //---------------------------------------------------------------------------------------
 
 
 
diff --git a/ourbackend.java b/ourbackend.java
index d1f721d..86d24cd 100644
--- a/ourbackend.java
+++ b/ourbackend.java
@@ -214,14 +214,45 @@ public boolean isFullCourse(int courseID) {
     /*
     this method to check if the course is full or not
      */
-    return false;
+    Courses current = headcourse; // starting from the head of te course.
+
+    while (current != null) {
+        if (current.courseID == courseID) { // To check if the current course matches the course ID entered
+            if (current.currentEnrollment >= current.maxCapacity) { // To check if it has reached the full capacity
+                System.out.println("Course ID " + courseID + " is full.");
+            } else {
+                System.out.println("Course ID " + courseID + " is not full. Current enrollment: " + current.currentEnrollment + " out of " + current.maxCapacity);
+            }
+            return true; // Course found
+
+        }
+        current = current.nextCourse;
+    }
+
+    System.out.println("Course with ID " + courseID + " not found.");
+    return false; // Return false if the course is not found
 }
 //------------------------------------------------------------
 public boolean isNormalStudent(int studentID) {
     /*
     this method to check if the student is normal or not
      */
-    return false;
+    Student current = headstudent; // starting from the head of the student.
+    while (current != null) {
+        if (current.studentID == studentID) { // To check if the current student matches the student ID entered
+            if (current.nextStudent == null) { // To check if it has reached the full capacity
+                System.out.println("Student ID " + studentID + " is a normal student.");
+            } else {
+                System.out.println("Student ID " + studentID + " is not a normal student. Current enrollment: " + current.nextStudent.studentID);
+            }
+            return true; // Student found
+
+        }
+        current = current.nextStudent;
+    }
+    System.out.println("Student with ID " + studentID + " not found.");
+    return false; // Return false if the student is not found
+
 }
 //----------------------------------------------------------------
 public void undoEnrollment() {
@@ -234,7 +265,9 @@ public void undoEnrollment() {
 public void redoEnrollment() {
     /*
     this method to redo enrollment
-     */
+    */ 
+    
 }
 //-------------------------------------------------------------------
-}
\ No newline at end of file
+}
+


Reviews:
user: login: sourcery-ai[bot]
body: Hey @Farouk12385 - I've reviewed your changes - here's some feedback:

**Overall Comments**:
- Consider extracting the repeated course/student search logic into a separate helper method.
- Avoid printing directly to `System.out` from within these methods; instead, return a value and let the calling code handle output.

<details>
<summary>Here's what I looked at during the review</summary>

- 🟡 **General issues**: 3 issues found
- 🟢 **Security**: all looks good
- 🟢 **Testing**: all looks good
- 🟢 **Complexity**: all looks good
- 🟢 **Documentation**: all looks good
</details>

***

<details>
<summary>Sourcery is free for open source - if you like our reviews please consider sharing them ✨</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20got%20an%20instant%20code%20review%20from%20%40SourceryAI%2C%20and%20it%20was%20brilliant%21%20It%27s%20free%20for%20open%20source%20and%20has%20a%20free%20trial%20for%20private%20code.%20Check%20it%20out%20https%3A//sourcery.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20got%20an%20instant%20code%20review%20from%20%40SourceryAI%2C%20and%20it%20was%20brilliant%21%20It%27s%20free%20for%20open%20source%20and%20has%20a%20free%20trial%20for%20private%20code.%20Check%20it%20out%20https%3A//sourcery.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https://sourcery.ai)
- [Facebook](https://www.facebook.com/sharer/sharer.php?u=https://sourcery.ai)

</details>

<sub>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
</sub>
state: COMMENTED
author_association: NONE
submitted_at: 2025-04-21T20:33:45Z

Review comments:
diff_hunk: @@ -214,14 +214,45 @@ public boolean isFullCourse(int courseID) {
     /*
     this method to check if the course is full or not
      */
-    return false;
+    Courses current = headcourse; // starting from the head of te course.
path: ourbackend.java
user: login: sourcery-ai[bot]
body: **suggestion (bug_risk):** The isFullCourse method returns true as soon as a course is found, regardless of whether it's full.

The method name suggests that it should return a boolean indicating if the course is actually full. Returning true on course discovery, even when the course has available capacity, might be counterintuitive. Consider returning true only when currentEnrollment >= maxCapacity, and false otherwise.

Suggested implementation:

```java
            if (current.courseID == courseID) { // To check if the current course matches the course ID entered
                if (current.currentEnrollment >= current.maxCapacity) { // To check if it has reached full capacity
                    System.out.println("Course ID " + courseID + " is full.");
                    return true; // Course is full
                } else {
                    System.out.println("Course ID " + courseID + " is not full. Current enrollment: " + current.currentEnrollment + " out of " + current.maxCapacity);
                    return false; // Course is not full
                }

```

Ensure that the method’s return type is boolean and that the return at the end of the method (if the loop completes without finding a matching course) is handled appropriately.
created_at: 2025-04-21T20:33:45Z
author_association: NONE
diff_hunk: @@ -214,14 +214,45 @@ public boolean isFullCourse(int courseID) {
     /*
     this method to check if the course is full or not
      */
-    return false;
+    Courses current = headcourse; // starting from the head of te course.
+
+    while (current != null) {
+        if (current.courseID == courseID) { // To check if the current course matches the course ID entered
+            if (current.currentEnrollment >= current.maxCapacity) { // To check if it has reached the full capacity
+                System.out.println("Course ID " + courseID + " is full.");
+            } else {
+                System.out.println("Course ID " + courseID + " is not full. Current enrollment: " + current.currentEnrollment + " out of " + current.maxCapacity);
+            }
+            return true; // Course found
+
+        }
+        current = current.nextCourse;
+    }
+
+    System.out.println("Course with ID " + courseID + " not found.");
+    return false; // Return false if the course is not found
 }
 //------------------------------------------------------------
 public boolean isNormalStudent(int studentID) {
     /*
     this method to check if the student is normal or not
      */
-    return false;
+    Student current = headstudent; // starting from the head of the student.
path: ourbackend.java
user: login: sourcery-ai[bot]
body: **suggestion:** The isNormalStudent logic is confusing regarding its return value and messaging.

Currently the method prints a message indicating whether the student is normal based on the presence of nextStudent, but it returns true if the student is found regardless of that condition. If the intent of the method is to determine if a student is ‘normal’, then the return value and printed message should reflect the actual condition rather than just the existence of the student in the list.
created_at: 2025-04-21T20:33:45Z
author_association: NONE
diff_hunk: @@ -214,14 +214,45 @@ public boolean isFullCourse(int courseID) {
     /*
     this method to check if the course is full or not
      */
path: ourbackend.java
user: login: sourcery-ai[bot]
body: **nitpick:** The redoEnrollment method contains an odd comment termination block.

The comment block seems to end with '*/' on an added line, leaving the method body empty. It would be clearer either to remove the block if not needed or to ensure the intended implementation is in place.
created_at: 2025-04-21T20:33:45Z
author_association: NONE

PR comments:
user: login: sourcery-ai[bot]
created_at: 2025-04-21T20:32:36Z
body: <!-- Generated by sourcery-ai[bot]: start review_guide -->

## Reviewer's Guide by Sourcery

This pull request implements the `isFullCourse` and `isNormalStudent` methods, updates the `Courses` class to include capacity and enrollment information, and updates the `README.md` file to reflect the completion of certain methods. Additionally, a CODEOWNERS file was added.

_No diagrams generated as the changes look simple and do not need a visual representation._

### File-Level Changes

| Change | Details | Files |
| ------ | ------- | ----- |
| Implemented methods to check if a course is full and if a student is considered a 'normal' student. | <ul><li>Added `isFullCourse` method to check course capacity.</li><li>Added `isNormalStudent` method to check student status.</li><li>Included checks for null values to prevent errors.</li><li>Added print statements to indicate whether a course is full or a student is normal.</li></ul> | `ourbackend.java` |
| Updated the Courses class to include maxCapacity and currentEnrollment fields. | <ul><li>Added `maxCapacity` field to store the maximum number of students for a course.</li><li>Added `currentEnrollment` field to track the current number of enrolled students.</li><li>Initialized `maxCapacity` to 30 in the constructor.</li><li>Initialized `currentEnrollment` to 0 in the constructor.</li></ul> | `Courses.java` |
| Updated the README.md file to reflect the completion of certain methods. | <ul><li>Marked 'enrool student in course' as done by rashad.</li><li>Marked 'if full course or not' and 'is normal student or not' as done by aly.</li></ul> | `README.md` |
| Added a CODEOWNERS file. | <ul><li>Added a CODEOWNERS file.</li></ul> | `CODEOWNERS` |

---

<details>
<summary>Tips and commands</summary>

#### Interacting with Sourcery

- **Trigger a new review:** Comment `@sourcery-ai review` on the pull request.
- **Continue discussions:** Reply directly to Sourcery's review comments.
- **Generate a GitHub issue from a review comment:** Ask Sourcery to create an
  issue from a review comment by replying to it. You can also reply to a
  review comment with `@sourcery-ai issue` to create an issue from it.
- **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull
  request title to generate a title at any time. You can also comment
  `@sourcery-ai title` on the pull request to (re-)generate the title at any time.
- **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in
  the pull request body to generate a PR summary at any time exactly where you
  want it. You can also comment `@sourcery-ai summary` on the pull request to
  (re-)generate the summary at any time.
- **Generate reviewer's guide:** Comment `@sourcery-ai guide` on the pull
  request to (re-)generate the reviewer's guide at any time.
- **Resolve all Sourcery comments:** Comment `@sourcery-ai resolve` on the
  pull request to resolve all Sourcery comments. Useful if you've already
  addressed all the comments and don't want to see them anymore.
- **Dismiss all Sourcery reviews:** Comment `@sourcery-ai dismiss` on the pull
  request to dismiss all existing Sourcery reviews. Especially useful if you
  want to start fresh with a new review - don't forget to comment
  `@sourcery-ai review` to trigger a new review!
- **Generate a plan of action for an issue:** Comment `@sourcery-ai plan` on
  an issue to generate a plan of action for it.

#### Customizing Your Experience

Access your [dashboard](https://app.sourcery.ai) to:
- Enable or disable review features such as the Sourcery-generated pull request
  summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.

#### Getting Help

- [Contact our support team](mailto:support@sourcery.ai) for questions or feedback.
- Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information.
- Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).

</details>

<!-- Generated by sourcery-ai[bot]: end review_guide -->
author_association: NONE
user: login: Farouk12385
created_at: 2025-04-21T20:32:47Z
body: edit
author_association: OWNER