Answer to Question #335731 in Python for Jeanne

Question #335731

Clas calld Author is desiged tomodel book author.Contan:3private intance varable:name(String),email(String),and gender(char of either 'm' or 'f');An__init__() toinitalize the nme,email,gendr with given value Getters/Setters: getName(),getEmail(),setEmail(),and getGender()(There areno seter for nameandgender, asthese atribute canotbe changd.)A__str__() metodthat return prntable string oftht objct with folowing formt:

"Author[name=?,email=?,gender=?]"

e.g., "Author[name=Tan Ah Teck,email=ahTeck@somewhere.com,gender=m]". Write the Author clas.Writetest driver code totest all public functon e.g.,

ahTeck=Author("Tan Ah Teck", "ahteck@nowhere.com", 'm')#Test the  constructor

print(ahTeck) # Test __str__()

ahTeck.setEmail("paulTan@nowhere.com") #Test setter

print("Name is: ", ahTeck.getName())#Test getter

print("Email is: ", ahTeck.getEmail())#Test getter

print("Gender is: ",ahTeck.getGender())#Test getter.


1
Expert's answer
2022-04-30T05:39:32-0400
class Author:

    def __init__(self, name, email, gender):
        self.__name = name
        self.__email = email
        self.__gender = gender

    def getName(self):
        return self.__name

    def getEmail(self):
        return self.__email

    def setEmail(self, email):
        self.__email = email

    def getGender(self):
        return self.__gender

    def __str__(self):
        return f'Author[name={self.__name},email={self.__email},gender={self.__gender}]'

ahTeck = Author("Tan Ah Teck", "ahteck@nowhere.com", 'm')
ahTeck.setEmail("paulTan@nowhere.com")
print(ahTeck)
print("Name is:", ahTeck.getName())
print("Email is:", ahTeck.getEmail())
print("Gender is:", ahTeck.getGender())

OUTPUT:
Author[name=Tan Ah Teck,email=ahteck@nowhere.com,gender=m]
Author[name=Tan Ah Teck,email=paulTan@nowhere.com,gender=m]
Name is: Tan Ah Teck
Email is: paulTan@nowhere.com
Gender is: m




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS