Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

  • 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:
    1. 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.
    2. The __lt__ method for an OnlineStudent object should return true if
      self.username  
    3. The add_group_member method adds the username of a new study group member to the study_group instance member list.
    4. 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.
Student +username int +last_name: str +first_name str +phone str + year: int _init_(self: Student, i: int, last: str, first: str, ph:str, yr: int) _str_(self: Student) _repr__(self: Student) +update_year(self Student) Online Student +email:str + study_group: strl] -init-(self: OnlineStudent, i : int, lapt : str, first: str. ph : str, yr : int, em : str) -_str_(self: OnlineStudent) _repr__(self: OnlineStudent) lt-(self. OnlineStudent, other. OnlineStudent) + add group member self: OnlineStudent, member id: int) Student +username int +last_name: str +first_name str +phone str + year: int _init_(self: Student, i: int, last: str, first: str, ph:str, yr: int) _str_(self: Student) _repr__(self: Student) +update_year(self Student) Online Student +email:str + study_group: strl] -init-(self: OnlineStudent, i : int, lapt : str, first: str. ph : str, yr : int, em : str) -_str_(self: OnlineStudent) _repr__(self: OnlineStudent) lt-(self. OnlineStudent, other. OnlineStudent) + add group member self: OnlineStudent, member id: int)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Do not pay him, wait until I come

Answered: 1 week ago

Question

a. How do you think these stereotypes developed?

Answered: 1 week ago

Question

7. Describe phases of multicultural identity development.

Answered: 1 week ago