Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Goal: Implement and test the OnlineStudent class as shown in the Student/OnlineStudent UML Diagram. Relevant Examples: EmployeeHierarchy PersonArray Input Files: students.txt study-groups.txt The study_group instance
- Goal: Implement and test the OnlineStudent class as shown in the Student/OnlineStudent UML Diagram.
- Relevant Examples: EmployeeHierarchy PersonArray
- Input Files: students.txt study-groups.txt
- The study_group instance variable is a list that contains the username values of the other members in the student's study group.
- Details:
- Implement the OnlineStudent class in the module onlinestudent.py as specified by the Student/OnlineStudent UML Diagram. OnlineStudent is the derived class of the base class Student.
- The __lt__ method for an OnlineStudent object should return true if
self.username
- The add_group_member method adds the username of a new study group member to the study_group instance member list.
- Write a traditional test class test1.py (different than your test1 script in Project 4a) that tests the additional instance members of the OnlineStudent class that are not in the Student class:
__init__ __str__ __repr__ __lt__ email study_group add_group_member
__init__, __str__, and __repr__ are tested again in the OnlineStudent class because they are overridden methods.
- Convert your test1.py script to a unit test script test2.py.
- Write the script test3.py that creates and populates a list of OnlineStudent objects. It inputs a requested student, then prints the fields for that student, and also the username of each student in the student's study group. See the pseudocode in the next section.
- Here is a new type of for loop that you can use for this project:
# Instead of writing a loop like this fin = open("input-file", "r") line = fin.readline( ) while line != "": process line line = fin.readline( ) fin.close( ) # write it like this: fin = open("input-file", "r") for line in fin: process line fin.close( )
- Pseudocode for test3.py:
Initialize list to hold OnlineStudent objects, call it students. Open input file students.txt. For all lines in the input file Use split to extract the fields list. Assign variable names to fields. Create OnlineStudent object. Append object to list. End for. Close input file object. Sort array by username. Print list of OnlineStudent objects. Open input file study-groups.txt. For all lines in input file Use split to extract the fields list. For each student s in students list If s.username is equal to fields[0] For the index i in the range from 1 to length of fields list - 1 Append fields[1] to s.study_group list. End for. End if. End for. End for. For s in students' list Print s. Print usernames of study group members. End for. Input requested username. for each student s in students list If requested username is equal to s.username Print s. For t in s.study_group Print t End for. Close input file.
- Challenge Problem: Instead of printing the usernames of the students in the study group, print the first names of the students in the study group.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started