Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement in Python the Subscriber class modeled by the UML diagram provided bel

ID: 3717183 • Letter: I

Question

Implement in Python the Subscriber class modeled by the UML diagram provided below. Save in a file called MyClasses.py

Subscriber

name: string

yearOfBirth: int

phone: string

email: string

getName()

getAge()

getPhone()

getEmail()

Write a test program that does the following:

Read the file addresses.csv.

For each record, create an object with the information in the file. Note that the file has 3 records, so 3 objects must be dynamically created.

Print the name, email, and age in a tabulated format as shown below

Name                     Email                           Age

Elizi Moe               emoe@ncsu.edu           40

Ma Ta                    mta@yahoo.com          30

Diana Cheng          dcheng@asu.edu          48

Subscriber

name: string

yearOfBirth: int

phone: string

email: string

getName()

getAge()

getPhone()

getEmail()

Explanation / Answer

Python Code:

class Subscriber:
   """ Subscriber class definition """
  
   def __init__(self, name="", phone="", email="", yob=0):
       """ Constructor that assigns values to data member """
       self.__name = name;
       self.__yob = yob;
       self.__phone = phone;
       self.__email = email;
      
   def getName(self):
       """ Getter method for name """
       return self.__name;
  
   def getAge(self):
       """ Getter method for age """
       return (2018 - self.__yob);
      
   def getPhone(self):
       """ Getter method for phone """
       return self.__phone;
  
   def getEmail(self):
       """ Getter method for email """
       return self.__email;  
      
      
      
def main():
   """ Main function """
   # List that holds all subscribers
   subscribers = [];
      
   # Opening file
   with open("d:/Python/address.csv", "r") as fileReader:
       # Getting header
       header = fileReader.readline();
      
       # Reading data from file
       for line in fileReader:
           # Stripping new line and splitting on comma
           cols = (line.strip()).split(',');
           # Creating Subscriber class object
           sObj = Subscriber(cols[0], cols[1], cols[2], int(cols[3]));
           # Adding to list
           subscribers.append(sObj);
  
   # Testing subscribers list
   if len(subscribers) == 0:
       print(" Empty data.... ");
   else:
       # Printing header  
       print(" %-20s %-20s %-15s " %("Name", "Email","Age"));  
       # Printing subscribers list
       for obj in subscribers:
           print(" %-20s %-20s %-15d " %(obj.getName(), obj.getEmail(),obj.getAge()));  
          
# Calling main function          
main();

-----------------------------------------------------------------------------------------------------------------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote