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

Please help me with this question, the answer has to be in Python 3.x. I dont kn

ID: 3865699 • Letter: P

Question

Please help me with this question, the answer has to be in Python 3.x. I dont know where to begin or how to do it. Thanks!

7. The following problems relate to an email messaging system: Design a class Message that models an e-mail message. A message has a recipient, a sender, and a message text. Support the following methods: A constructor that takes the sender and recipient A method append that appends a line of text to the message body A method toString that makes the message into one long string like this (notice that each line is in a new line): "From: Harry Morgan To: Rudolf Reindeer Design a class Mailbox that stores e-mail messages, using the Message class from before. Implement the following methods: def addMessage(self, message) - def getMessage(self, index) - def removeMessage(self, index) Write a short program that uses the Message and Mailbox classes by making a Message, printing it and storing it in a Mailbox

Explanation / Answer

#!usr/python/bin

class Message:
    def __init__(self, sender, recipient, text):
         self.s = sender
         self.r = recipient
         self.t = text
    def append(self, line):
        self.t = self.t + "." + line
    def toString(self):
        print("From:",self.s)
        print("To:",self.r)
        print(self.t)

class Mailbox:
    def __init__(self):
         self.l = []

    def addMessage(self, msg):
        self.l.append(msg)

    def getMessage(self, index):
        return self.l[index]

    def deleteMessage(self, index):
        del self.l[index]

x = Message("John", "Harry", "Hi, I am fine")
y = Mailbox()
x.append(" How are you")
x.toString()
y.addMessage(x)
z = Message("","","")
z = y.getMessage(0)
z.toString()
y.deleteMessage(0)

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