Menu
Coddy logo textTech

E-러닝 플랫폼

Coddy Python 여정의 Object Oriented Programming 섹션에 포함된 레슨 — 64개 중 61번째.

challenge icon

챌린지

어려움

이 챌린지에서는 객체 지향 e-러닝 플랫폼 시스템을 구현합니다.

  • course.py - Course 클래스를 구현합니다.
  • student.py - Student 클래스를 구현합니다.
  • instructor.py - Instructor 클래스를 구현합니다.

치트 시트

이 레슨은 세 개의 주요 클래스를 사용하여 객체 지향 e-러닝 플랫폼 시스템을 구현하는 데 중점을 둡니다:

  • Course 클래스 - 플랫폼 내의 교육 과정을 나타냅니다
  • Student 클래스 - 강좌에 등록할 수 있는 학습자를 나타냅니다
  • Instructor 클래스 - 강좌를 생성하고 관리할 수 있는 강사를 나타냅니다

이 시스템은 실제 세계의 엔티티를 고유한 속성과 메서드를 가진 클래스로 모델링함으로써 객체 지향 프로그래밍 원칙을 보여줍니다.

직접 해보기

from course import Course
from student import Student
from instructor import Instructor

# 테스트 케이스 핸들러
test_case = input()

if test_case == "course_creation":
    # 다양한 정원을 가진 강좌 생성 테스트
    course1 = Course("Python 101", "Introduction to Python", 20)
    course2 = Course("Data Science", "Advanced data analysis techniques")
    
    print(f"Course 1: {course1.title}, Max Capacity: {course1.max_capacity}")
    print(f"Course 2: {course2.title}, Max Capacity: {course2.max_capacity}")
    print(f"Initial student count: {len(course1.students)}")

elif test_case == "student_enrollment":
    # 학생 수강 신청 프로세스 테스트
    course = Course("Python 101", "Introduction to Python", 2)
    student1 = Student("Alice", "alice@example.com")
    student2 = Student("Bob", "bob@example.com")
    student3 = Student("Charlie", "charlie@example.com")
    
    # 학생 등록
    result1 = student1.enroll(course)
    result2 = student2.enroll(course)
    result3 = student3.enroll(course)  # 실패해야 함 (정원 초과)
    
    print(f"Enrollment 1 result: {result1}")
    print(f"Enrollment 2 result: {result2}")
    print(f"Enrollment 3 result: {result3}")
    
    # 동일한 학생을 두 번 등록 시도
    result4 = student1.enroll(course)
    print(f"Re-enrollment result: {result4}")
    
    # 강좌 및 학생 상태 확인
    print(f"Course has {len(course.students)} students")
    print(f"Student 1 has {len(student1.enrolled_courses)} enrolled courses")

elif test_case == "student_unenrollment":
    # 학생 수강 취소 프로세스 테스트
    course = Course("Python 101", "Introduction to Python")
    student = Student("Alice", "alice@example.com")
    
    # 등록 후 취소
    student.enroll(course)
    print(f"Before unenroll: Course has {len(course.students)} students")
    print(f"Before unenroll: Student has {len(student.enrolled_courses)} courses")
    
    result = student.unenroll(course)
    print(f"Unenrollment result: {result}")
    
    print(f"After unenroll: Course has {len(course.students)} students")
    print(f"After unenroll: Student has {len(student.enrolled_courses)} courses")
    
    # 다시 취소 시도
    result = student.unenroll(course)
    print(f"Second unenrollment result: {result}")

elif test_case == "course_completion":
    # 강좌 수료 프로세스 테스트
    course = Course("Python 101", "Introduction to Python")
    student = Student("Alice", "alice@example.com")
    
    # 등록 및 수료
    student.enroll(course)
    print(f"Before completion: Enrolled in {len(student.enrolled_courses)} courses")
    print(f"Before completion: Completed {len(student.completed_courses)} courses")
    
    result = student.complete_course(course)
    print(f"Completion result: {result}")
    
    print(f"After completion: Enrolled in {len(student.enrolled_courses)} courses")
    print(f"After completion: Completed {len(student.completed_courses)} courses")
    
    # 강좌 상태 확인
    print(f"Course has {len(course.students)} active students")
    print(f"Course has {len(course.completed_students)} completed students")

elif test_case == "instructor_assignment":
    # 강사 배정 테스트
    course = Course("Python 101", "Introduction to Python")
    instructor = Instructor("Dr. Smith", "smith@example.edu", "Computer Science")
    
    print(f"Before assignment: Instructor has {len(instructor.courses)} courses")
    print(f"Before assignment: Course instructor is {course.instructor}")
    
    result = instructor.assign_to_course(course)
    print(f"Assignment result: {result}")
    
    print(f"After assignment: Instructor has {len(instructor.courses)} courses")
    print(f"After assignment: Course instructor is {course.instructor.name}")

elif test_case == "course_management":
    # 강좌 정원 관리 테스트
    course = Course("Limited Course", "Test capacity", 2)
    student1 = Student("Alice", "alice@example.com")
    student2 = Student("Bob", "bob@example.com")
    student3 = Student("Charlie", "charlie@example.com")
    
    # 강좌 정원 채우기
    student1.enroll(course)
    student2.enroll(course)
    result = student3.enroll(course)  # 실패해야 함
    print(f"Enrolling to full course: {result}")
    
    # 수강 취소로 자리 만들기
    student1.unenroll(course)
    result = student3.enroll(course)  # 이제 성공해야 함
    print(f"Enrolling after unenrollment: {result}")
    
    # 최종 상태 확인
    print(f"Final students in course: {len(course.students)}")
    print(f"Students are: {[s.name for s in course.students]}")

elif test_case == "integrated_test":
    # 전체 시스템 통합 테스트
    # 강좌 생성
    python_course = Course("Python 101", "Introduction to Python", 3)
    data_course = Course("Data Science", "Advanced data analysis", 2)
    
    # 학생 생성
    alice = Student("Alice", "alice@example.com")
    bob = Student("Bob", "bob@example.com")
    charlie = Student("Charlie", "charlie@example.com")
    
    # 강사 생성
    dr_smith = Instructor("Dr. Smith", "smith@example.edu", "Computer Science")
    
    # 강사 배정
    dr_smith.assign_to_course(python_course)
    dr_smith.assign_to_course(data_course)
    
    # 학생 등록
    alice.enroll(python_course)
    bob.enroll(python_course)
    charlie.enroll(python_course)
    
    alice.enroll(data_course)
    bob.enroll(data_course)  # data_course 정원이 참
    
    # 강좌 수료
    alice.complete_course(python_course)
    
    # 시스템 상태 출력
    print("System State:")
    print(f"Python course has {len(python_course.students)} active students and {len(python_course.completed_students)} completed")
    print(f"Data course has {len(data_course.students)} active students")
    print(f"Dr. Smith teaches {len(dr_smith.courses)} courses")
    print(f"Alice is enrolled in {len(alice.enrolled_courses)} courses and completed {len(alice.completed_courses)}")
    print(f"Charlie is enrolled in {len(charlie.enrolled_courses)} courses")

elif test_case == "edge_cases":
    # 예외 케이스 테스트
    course = Course("Small Course", "Test edge cases", 1)
    student1 = Student("Alice", "alice@example.com")
    student2 = Student("Bob", "bob@example.com")
    
    # 정확히 정원만큼 등록 테스트
    result1 = student1.enroll(course)
    result2 = student2.enroll(course)  # 실패해야 함
    print(f"Enrollment at capacity: {result1}")
    print(f"Enrollment beyond capacity: {result2}")
    
    # 등록되지 않은 강좌의 수료 테스트
    other_course = Course("Other Course", "Not enrolled")
    result3 = student1.complete_course(other_course)
    print(f"Complete non-enrolled course: {result3}")
    
    # 등록되지 않은 강좌의 수강 취소 테스트
    result4 = student2.unenroll(course)
    print(f"Unenroll from non-enrolled course: {result4}")
    
    # 강사 재배정 테스트
    instructor1 = Instructor("Dr. Smith", "smith@example.edu", "Python")
    instructor2 = Instructor("Dr. Jones", "jones@example.edu", "Java")
    
    instructor1.assign_to_course(course)
    print(f"First instructor: {course.instructor.name}")
    
    instructor2.assign_to_course(course)
    print(f"After reassignment: {course.instructor.name}")

elif test_case == "capacity_limits":
    # 정원 제한 테스트
    zero_capacity = Course("Empty Course", "No students allowed", 0)
    student = Student("Alice", "alice@example.com")
    
    result1 = student.enroll(zero_capacity)
    print(f"Enroll in zero-capacity course: {result1}")
    
    large_capacity = Course("Huge Course", "Many students", 1000)
    result2 = student.enroll(large_capacity)
    print(f"Enroll in large-capacity course: {result2}")
    print(f"Large course has capacity for {large_capacity.max_capacity} students")

elif test_case == "multiple_courses":
    # 여러 강좌를 수강하는 학생 테스트
    student = Student("Alice", "alice@example.com")
    course1 = Course("Python 101", "Intro to Python")
    course2 = Course("Java 101", "Intro to Java")
    course3 = Course("C++ 101", "Intro to C++")
    
    # 모든 강좌에 등록
    student.enroll(course1)
    student.enroll(course2)
    student.enroll(course3)
    print(f"Enrolled in {len(student.enrolled_courses)} courses")
    
    # 일부 강좌 수료
    student.complete_course(course1)
    student.complete_course(course2)
    print(f"After completion: Enrolled in {len(student.enrolled_courses)} courses")
    print(f"After completion: Completed {len(student.completed_courses)} courses")
    
    # 특정 강좌 확인
    enrolled_titles = [c.title for c in student.enrolled_courses]
    completed_titles = [c.title for c in student.completed_courses]
    print(f"Still enrolled in: {enrolled_titles}")
    print(f"Completed: {completed_titles}")

elif test_case == "instructor_workload":
    # 여러 강좌를 담당하는 강사 테스트
    instructor = Instructor("Dr. Smith", "smith@example.edu", ["Python", "Java", "C++"])
    course1 = Course("Python 101", "Intro to Python")
    course2 = Course("Java 101", "Intro to Java")
    course3 = Course("C++ 101", "Intro to C++")
    
    # 모든 강좌에 배정
    instructor.assign_to_course(course1)
    instructor.assign_to_course(course2)
    instructor.assign_to_course(course3)
    
    print(f"Instructor teaches {len(instructor.courses)} courses")
    course_titles = [c.title for c in instructor.courses]
    print(f"Courses taught: {course_titles}")
    
    # 각 강좌에 강사가 제대로 배정되었는지 확인
    for i, course in enumerate([course1, course2, course3]):
        print(f"Course {i+1} instructor: {course.instructor.name}")

Object Oriented Programming의 모든 레슨