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

using python 3: i will give the code, my answer and feedback received to fixed t

ID: 3823782 • Letter: U

Question

using python 3: i will give the code, my answer and feedback received to fixed the issue. i always rate my answers

-here is my code:

-here is the feedback received

Ismael:

Please revise this program:

1. The class for the SMS_Inbox must be in its own file -- you can name it modSMS.py

2. The test program with the menu and the functions createMenu, isValidPhone, getValidInput, and the information for reading from the file must be in a separate file -- you could call it testSMS.py for example.

3. the SMS_Inbox class needs to have a countMessages method -- you haven't named that method properly.

4. When I chose to read from an input file, the program crashed. You were to ask the user for the filename, and then you must test to ensure that file exists.

5. print the inbox must print ALL of the information, not just the messages

6. missing preconditions and descriptions for the functions and methods.

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

Program 11: SMS Class Create a class that simulates the behavior of a phone text messaging inbox. (20 pts) Class SMS inbox msgList: list of subTuples where each tuple contains the information about a message: (hasBeenRead:boolean, sender Phone string, arrivalTime:datetime, msgText:string) Example of what msgList might contain after 2 messages were added and the second one has been ead already (False, '111-222-3333', 2017-01 -31 14:35:01, meet me at MSUM True, '111-345-3678', 2017-01-01 12:30:32, 'back at noon) constructor SMS Inbox( +getMsg List(): list of tuples +str(): String #prints the messages in the inbox, one per line +addNewArrival sender Phone: String, arriveTime: datetime, msgText:String) +count Messages integer Create a testSMS.py program to test the SMS Inbox class thoroughly 1. Create an inbox for Joe's messages by calling the constructor: joelnbox SMS Inbox 2. Ask the user if they would like to read data from a textfile. Ifthey do, use it to populate Joe's inbox by reading information from the text file and using the al method 3. Use the createMenu function (with 2 parameters -titleOfMenu,optionList) to create the menu and print the string it returns so that the following menu appears: 1. Send a message 2. Print the inbox 3. Print the number of messages in the inbox 4. Quit 4. Use yourgetValidChoice function with 3 parameters msg, start, end) to obtain a valid choice from the user. Remember that the getValidChoice function ensures that the user's menu choice is numeric and in the appropriate range and RETURNS the numeric choice 5. Based on the user's menu choice, use the appropriate method from your SMS Inbox class to produce the desired results. Format for the text file: Example text file: phone Number 111-222-3333 year, month, day, hour, minute, second 2017, 1, 31, 14, 35, 1 meet me at MSUM message 111-345-3678 2017, 10, 14, 9, 30, 59 In class talk later

Explanation / Answer

modSMS.py

from datetime import datetime


class SMS_Inbox:
def __init__(self):
self._msgList = []

def getMsgList(self):
return self._msgList

def __str__(self):
result = ""
for val in self._msgList:
result += "Sender phone: " + str(val[1]) + " Arrival Time: " + str(val[2]) + " Message Text: " + str(val[3]) + " "
return result

def addNewArrival(self, senderPhone, arriveTime, msgText):
"""
  
:param senderPhone:
:param arriveTime:
:param msgText:
:return:
"""
  
self._msgList.append((False, senderPhone, arriveTime, msgText))

def countMessages(self):
return len(self._msgList)

testSMS.py

from pathlib import Path
from modSMS import SMS_Inbox

def createMenu(titleOfMenu, optionList):
print(titleOfMenu)
for i, option in enumerate(optionList):
print(i + 1, option)


def getValidChoice(message, start, end):
while True:
choice = int(input(message + ":"))
if start <= choice <= end:
return choice;
else:
print(message, "between", start, " and ", end)

if __name__ == '__main__':

joeInbox = SMS_Inbox()
user_choice = input("would you like to read data from text file?y/n: ")
filename = "inbox.txt"
if user_choice.lower() == 'y':
while True:
filename = input("Enter filename: ")
my_file = Path(filename)
if my_file.is_file():
break
else:
print("File doesn't exist. Please try again!")
  
with open("inbox.txt", 'r') as f:
count = 0
while True:
phone_number = f.readline().strip()
if not phone_number:
break
year, month, day, hour, minute, second = f.readline().strip().split(",")
date_time = datetime(int(year), int(month), int(day), int(hour), int(minute), int(second))
message = f.readline().strip()
joeInbox.addNewArrival(phone_number, date_time, message)

while True:
createMenu("SMS", ["Send a message", "Print the inbox", "Print total number of message in inbox", "Quit"])
menu_choice = getValidChoice("Enter your choice ", 1, 4)
if menu_choice == 4:
break
elif menu_choice == 1:
phone_number = input("Enter phone Number");
date_time = datetime.now()
# year, month, day, hour, minute, second = input(
# "Enter year, month, day, hour, minute, second spearetd by comma:").split(",")
# date_time = datetime(int(year), int(month), int(day), int(hour), int(minute), int(second))
message = input("Enter message:")
joeInbox.addNewArrival(phone_number, date_time, message)
elif menu_choice == 2:
print(joeInbox)
elif menu_choice == 3:
print(joeInbox.countMessages())

# Code link: https://goo.gl/4j6Aj5

Am not sure what all needed to be added. I guess its better that whoever code this should add comment as he will have better context.