From a80a1c47bf55b2f90d7a58548621e4585793d93a Mon Sep 17 00:00:00 2001 From: Saba_frm Date: Mon, 20 Apr 2026 21:16:24 +0330 Subject: [PATCH] workshop done --- .gitignore | 30 ++++++++++++++++++ .idea/.gitignore | 10 ++++++ .idea/misc.xml | 6 ++++ .idea/modules.xml | 8 +++++ Workshop 02 - IntroToOOP.iml | 11 +++++++ src/Course.java | 43 ++++++++++++++++++++++++++ src/Main.java | 47 ++++++++++++++++++++++++++++ src/RegistrationSystem.java | 36 ++++++++++++++++++++++ src/Student.java | 59 ++++++++++++++++++++++++++++++++++++ 9 files changed, 250 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 Workshop 02 - IntroToOOP.iml create mode 100644 src/Course.java create mode 100644 src/Main.java create mode 100644 src/RegistrationSystem.java create mode 100644 src/Student.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..13275f1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ +.kotlin + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0fb127f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..99ba413 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Workshop 02 - IntroToOOP.iml b/Workshop 02 - IntroToOOP.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Workshop 02 - IntroToOOP.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Course.java b/src/Course.java new file mode 100644 index 0000000..a0c0c37 --- /dev/null +++ b/src/Course.java @@ -0,0 +1,43 @@ + +public class Course { + private String courseName; + private String courseCode; + private int capacity; + + public Course(String courseName, String courseCode, int capacity) + { + this.courseName = courseName; + this.courseCode = courseCode; + this.capacity = capacity; + } + + public String getCourseName() + { + return courseName; + } + + public String getCourseCode() + { + return courseCode; + } + + public int getCapacity() + { + return capacity; + } + + public boolean reduceCapacity() + { + if (capacity > 0) + { + capacity--; + return true; + } + return false; + } + + public void increaseCapacity() + { + capacity++; + } +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..533b8c8 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,47 @@ +import java.util.Scanner; + +public class Main +{ + public static void main(String[] args) + { + + Scanner input = new Scanner(System.in); + + // گرفتن اطلاعات دانش‌آموز از ورودی + System.out.print("Enter student name: "); + String name = input.nextLine(); + + System.out.print("Enter student ID: "); + String studentId = input.nextLine(); + + Student s1 = new Student(name, studentId); + + // ساخت 3 درس + Course c1 = new Course("Advanced Programming", "AP1404", 2); + Course c2 = new Course("Data Structures", "DS1404", 1); + Course c3 = new Course("Database Systems", "DB1404", 3); + + // ساخت سیستم ثبت نام + RegistrationSystem sys = new RegistrationSystem(); + + // اضافه کردن درس‌ها به سیستم + sys.addCourseToSystem(c1); + sys.addCourseToSystem(c2); + sys.addCourseToSystem(c3); + + // ثبت‌نام خودکار دانش‌آموز + s1.addCourse(c1); + s1.addCourse(c2); + + // حذف یکی از درس‌ها + s1.dropCourse(c2); + + // نمایش درس‌های ثبت‌شده + System.out.println("\nFinal registered courses:"); + s1.showRegisteredCourses(); + + // نمایش ظرفیت باقی‌مانده‌ی همه درس‌ها + System.out.println("\nRemaining course capacities:"); + sys.showAllCourses(); + } +} diff --git a/src/RegistrationSystem.java b/src/RegistrationSystem.java new file mode 100644 index 0000000..4fcfb6c --- /dev/null +++ b/src/RegistrationSystem.java @@ -0,0 +1,36 @@ +import java.util.ArrayList; + +public class RegistrationSystem { + private ArrayList courses; + + public RegistrationSystem() { + courses = new ArrayList<>(); + } + + public void addCourseToSystem(Course c) { + // Add the course to the system + courses.add(c); + } + + public Course findCourseByCode(String code) { + // Search for a course by course code + for (Course c : courses) { + if (c.getCourseCode().equals(code)) { + return c; + } + } + return null; + } + + public void showAllCourses() { + // Print all courses in the system + for (Course c : courses) { + System.out.println( + c.getCourseName() + " - " + + c.getCourseCode() + + " | Remaining capacity: " + + c.getCapacity() + ); + } + } +} diff --git a/src/Student.java b/src/Student.java new file mode 100644 index 0000000..66ca250 --- /dev/null +++ b/src/Student.java @@ -0,0 +1,59 @@ +import java.util.ArrayList; + +public class Student { + private String name; + private String studentId; + private ArrayList registeredCourses; + + public Student(String name, String studentId) + { + this.name = name; + this.studentId = studentId; + this.registeredCourses = new ArrayList<>(); + } + + public String getName() + { + return name; + } + + public String getStudentId() + { + return studentId; + } + + public boolean addCourse(Course c) + { + // Check capacity > 0 + if (c.getCapacity() > 0) + { + registeredCourses.add(c); + c.reduceCapacity(); + return true; + } + return false; + } + + public boolean dropCourse(Course c) + { + if (registeredCourses.remove(c)) + { + c.increaseCapacity(); + return true; + } + return false; + } + + public void showRegisteredCourses() + { + System.out.println("Registered Courses for " + name + ":"); + if (registeredCourses.isEmpty()) + { + System.out.println("No courses registered."); + } + for (Course c : registeredCourses) + { + System.out.println(c.getCourseName() + " - " + c.getCourseCode()); + } + } +}