4 Commits
Author SHA1 Message Date
MehrdadShirvani 2463d1ed91 Merge pull request 'develop' (#1) from develop into main
Full Mark 100/100
2026-05-15 12:36:25 +00:00
bitahajati 3195b392af changes in class Main 2026-04-20 22:59:57 +03:30
bitahajati cd3436131d changes in class RegistrationSystem 2026-04-20 22:44:03 +03:30
bitahajati e8bafc4140 changes in class Student 2026-04-20 22:40:21 +03:30
3 changed files with 99 additions and 29 deletions
+21 -9
View File
@@ -1,14 +1,26 @@
package CourseRegistrationStarter;
public class Main {
public static void main(String[] args) {
// TODO:
// 1. Create at least 3 courses
// 2. Create 1 student
// 3. Create a registration system
// 4. Add courses to the system
// 5. Register the student in some courses
// 6. Drop one course
// 7. Print the final registered course list
public static void main(String[] args)
{
Course c1 = new Course("Advanced Programming","4041",40);
Course c2 = new Course("Math","4042",50);
Course c3 = new Course("English","4043",20);
RegistrationSystem registrationSystem = new RegistrationSystem();
registrationSystem.addCourseToSystem(c1);
registrationSystem.addCourseToSystem(c2);
registrationSystem.addCourseToSystem(c3);
Student st1 = new Student("Lionel Messi","404222010");
st1.addCourse(c1);
st1.addCourse(c2);
st1.addCourse(c3);
st1.dropCourse(c2);
st1.showRegisteredCourses();
}
}
@@ -1,24 +1,54 @@
package CourseRegistrationStarter;
import java.util.ArrayList;
public class RegistrationSystem {
public class RegistrationSystem
{
private ArrayList<Course> courses;
public RegistrationSystem() {
courses = new ArrayList<>();
}
public void addCourseToSystem(Course c) {
// TODO: Add the course to the system
public void addCourseToSystem(Course c)
{
courses.add(c);
}
public Course findCourseByCode(String code) {
// TODO: Search for a course by course code
// Return the matching course if found, otherwise return null
public Course findCourseByCode(String code)
{
if(courses.isEmpty())
{
System.out.println("NOTHING HAS FOUND !");
return null;
}
else
{
for(int i = 0; i < courses.size(); i++)
{
Course c = courses.get(i);
if(code.equals(c.getCourseCode()))
{
return c;
}
}
}
System.out.println("NOTHING HAS FOUND !");
return null;
}
public void showAllCourses() {
// TODO: Print all courses in the system
public void showAllCourses()
{
if(courses.isEmpty())
{
System.out.println("NOTHING HAS FOUND !");
}
for(int i = 0; i < courses.size(); i++)
{
Course c = courses.get(i);
System.out.println("Course "+ (i + 1) + " : " + c.getCourseName()
+ " | code : " + c.getCourseCode()
+ " | cpacity : " + c.getCapacity());
}
}
}
+39 -11
View File
@@ -1,12 +1,15 @@
package CourseRegistrationStarter;
import java.util.ArrayList;
public class Student {
public class Student
{
private String name;
private String studentId;
private ArrayList<Course> registeredCourses;
private int limit = 15;
public Student(String name, String studentId) {
public Student(String name, String studentId)
{
this.name = name;
this.studentId = studentId;
this.registeredCourses = new ArrayList<>();
@@ -20,20 +23,45 @@ public class Student {
return studentId;
}
public boolean addCourse(Course c) {
// TODO: Register the student in the course if capacity allows
// Return true if registration was successful, otherwise false
public boolean addCourse(Course c)
{
if(registeredCourses.contains(c) || c.getCapacity() == 0)
{
return false;
}
else if(registeredCourses.size() <= limit && c.getCapacity() > 0)
{
c.reduceCapacity();
registeredCourses.add(c);
return true;
}
return false;
}
public boolean dropCourse(Course c) {
// TODO: Remove the course from the student's list
// Restore the course capacity if removal was successful
// Return true if the course was dropped, otherwise false
public boolean dropCourse(Course c)
{
if(registeredCourses.contains(c))
{
registeredCourses.remove(c);
c.increaseCapacity();
return true;
}
return false;
}
public void showRegisteredCourses() {
// TODO: Print all registered courses
public void showRegisteredCourses()
{
if(registeredCourses.size() > 0)
{
System.out.println("Registered Courses : ");
for(int i = 0; i < registeredCourses.size(); i++) {
Course c = registeredCourses.get(i);
System.out.println(c.getCourseName());
}
}
else
{
System.out.println("NO COURSES !");
}
}
}