how do you answer this in python
Problem: Define Classes Describing Students, Professors, and Courses For this problem you will be defining three classes, Student, Professor, and Course. For each, you will need to define the__init and_str__ methods to respectively initialize objects in the classes and to print them. The Student class has four attributes, three of which are passed to it at instance initialization. The first three are the student's uni (a string), their name (a string), and their year in school (an integer from 1 to 4). The fourth should be an attribute which is the list of courses they are taking, which should be set to an empty list at initialization. The Professor class also has four attributes, three of which are passed to it at instance initialization. These three are the professor's uni (a string), their name (string), and their office (also a string). The fourth should be also an attribute which is the list of courses they are teaching, which should be set to an empty list at initialization. The Course class has five attributes, four of which are passed to it at instance initialization. These four are the course number (a string), the professor (which is a professor object), the meeting time (also a string) and the room (also a string). The fifth should be an attribute which is a which is a list of the unis of the students in the course and which should be set to an empty list at initialization. When you pass a professor object to the Course class to initialize a Course object, you should add the course number of that course to the list of courses that the professor teaches, inside the professor object. You should also add an enroll method to both the Course and Student classes. This should work by passing a Course object to the method as a parameter (when called on a Student instance) or by passing a Student object to the method as a parameter (when called on a Course instance). This method should add the student's uni to the list of students enrolled in the course and add the course number to the list of courses that the student is enrolled in. After defining these classes, you should be able to run the following code in your main program:
I # create three students, each with uni, name, and year in school Mary=Student ("mw1111", "Mary Woods", 1) Vinod=Student ("vk1023", "Vinod Khosla",3) Jane=Student("jm1267","Jane Martinez", 2) # create two professors, each with uni, name, and office Joe=Professor('jw2222","Joe Wang", "WWH 417") Janine=Professor("jt8764","Janine Tanaka","WWH 419") # create a course taught by Joe Wang and add two students to it # note it is initialized with course number, a professor object, a meeting time and a meeting room cs0002=Course("CS 0002",Joe, "MW 11-12:15","Silver 201") cs0002.enroll (Mary) cs0002.enroll(Vinod) # create a course taught by Janine Tanaka and add two students to it cs0101=Course("CS 0101",Janine, "TR 11-12:15","Silver 409") cs0101.enroll (Vinod) # one way to enroll a student Jane.enroll(cs0101) # the other way to enroll a student # print out all of the objects (the print function calls # the str method in each case) print (Mary) print (Vinod) print (Jane) print (Janine) print(Joe) print(cs0002) print(cs0101) and get the following output: Mary Woods is a student with uni mw1111 in year 1 at NYU, enrolled in the following courses: ['CS 0002']. Vinod Khosla is a student with uni vk1023 in year 3 at NYU, enrolled in the following courses: ['CS 0002', 'CS 0101']. Jane Martinez is a student with uni jm1267 in year 2 at NYU, enrolled in the following courses: ['CS 0101']. Janine Tanaka is a professor at NYU with an office in WWH 419 and a uni of jt8764, teaching the following courses: ['CS 0101']. Joe Wang is a professor at NYU with an office in WWH 417 and a uni of jw2222, teaching the following courses: ['CS 0002']. Course CS 0002 is taught by Joe Wang and meets at MW 11-12:15 in Silver 201; student unis: ['mw1111', 'vk1023']. Course CS 0101 is taught by Janine Tanaka and meets at TR 11-12:15 in Silver 409; student unis: ['vk1023', 'jm1267').
Problem: Define Classes Describing Students, Professors, and Courses For this problem you will be defining three classes
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Problem: Define Classes Describing Students, Professors, and Courses For this problem you will be defining three classes
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!