Question

python programming

Student + last_name: str +first_name: str +phone str + year: int -init-(self: Student, i : int, last: str, first: str, ph : s

  • Goal: Implement and test the OnlineStudent class as shown in the Student/OnlineStudent UML Diagram.
  • 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 classStudent.
    2. The __lt__ method for an OnlineStudent object should return true if
      self.username < other.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.

students.txt

mcarter,Carter,Marilyn,312/473-4837,1,[email protected]
ggraber,Graber,Gary,312/837-2837,3,[email protected]
ccarpent,Carpenter,Carrie,312/377-2873,2,[email protected]
ccheng,Cheng,Sam,312/272-4473,1,[email protected]
obooker,Booker,Olivia,312/928-3980,4,[email protected]
rscanchez,Sanchez,Ricardo,312/838-9928,2,[email protected]
cdharan,Dharan,Connor,312/263-3922,2,[email protected]
yboulet,Boulet,Yvette,312/235-3728,3,[email protected]
rbolger,Bolger,Raymond,312/663-3827,4,[email protected]
sstrickl,Strickland,Sheryl,312/878-9800,1,[email protected]

study-groups.txt

ccarpent,yboulet,obooker
yboulet,ccarpent,obooker
obooker,ccarpent,yboulet
ccheng,cdharan,rbolger,ggraber
cdharan,rbolger,ggraber,ccheng
rbolger,ggraber,ccheng,cdharan
ggraber,ccheng,cdharan,rbolger
mcarter,sstrickl
sstrickl,mcarter
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:(TESTING STUDENT CLASS)

class Student:
    def __init__(self,i,last,first,ph,yr):
        self.username = i
        self.last_name = last
        self.first_name = first
        self.phone = ph
        self.year = yr
    def __str__(self):
        return "Username: "+self.username+"\nName: "+self.first_name+" "+self.last_name+"\nPhone: "+self.phone+"\nYear: "+str(self.year)
    def __repr__(self):
        return f'Student("{self.username}", "{self.last_name}","{self.first_name}","{self.phone}",{self.year})'
    def update_year(self):
        self.year = int(input("Enter new value for year"))
        
def main():
    l = []
    fh = open('students.txt','r')
    for line in fh.readlines():
        i,last,first,ph,yr,mail = line.split(',')
        l.append(Student(i,last,first,ph,int(yr)))
    fh.close()
    for i in l:
        print(i)
main()
        
        

OUTPUT:

Username: mcarter Name: Marilyn Carter Phone: 312/473-4837 Year: 1 Username: ggraber Name: Gary Graber Phone: 312/837-2837 Ye

CODE:(TESTING ONLINESTUDENT CLASS)

class Student:
def __init__(self,i,last,first,ph,yr):
self.username = i
self.last_name = last
self.first_name = first
self.phone = ph
self.year = yr
def __str__(self):
return "Username: "+self.username+"\nName: "+self.first_name+" "+self.last_name+"\nPhone: "+self.phone+"\nYear: "+str(self.year)
def __repr__(self):
return f'Student("{self.username}", "{self.last_name}","{self.first_name}","{self.phone}",{self.year})'
def update_year(self):
self.year = int(input("Enter new value for year"))
  
class OnlineStudent(Student):
def __init__(self,i,last,first,ph,yr,em):
super().__init__(i,last,first,ph,yr)
self.email = em
self.study_group = []
def __str__(self):
return super().__str__()+"\nEmail: "+self.email+"\nStudy group: "+self.study_group
def __lt__(self,other):
if self.username<other.username:
return True
else:
return False
def add_group_member(self,member_id):
self.study_group.append(member_id)
  
  

Add a comment
Know the answer?
Add Answer to:
python programming Goal: Implement and test the OnlineStudent class as shown in the Student/OnlineStudent UML Diagram....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in python please I need both unittest and traditional test Goal: Implement and test the OnlineStudent class as shown in...

    in python please I need both unittest and traditional test Goal: Implement and test the OnlineStudent class as shown in the Student/OnlineStudent UML Diagram. 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 classStudent. The __lt__ method for an OnlineStudent...

  • this is written in python Goal: Implement and test the Onlinestudent class as shown in the Student/OnlineStudent UML Dia...

    this is written in python Goal: Implement and test the Onlinestudent class as shown in the Student/OnlineStudent UML Diagram Relevant Examples: EmployeeHierarchy PersonArray Pet 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_1t__method for an...

  • PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything...

    PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything a course uses in a grading scheme, # like a test or an assignment. It has a score, which is assessed by # an instructor, and a maximum value, set by the instructor, and a weight, # which defines how much the item counts towards a final grade. def __init__(self, weight, scored=None, out_of=None): """ Purpose: Initialize the GradeItem object. Preconditions: :param weight: the weight...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT