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

SMS Class Create a class that simulates the behavior of a phone text messaging i

ID: 3810000 • Letter: S

Question

SMS Class Create a class that simulates the behavior of a phone text messaging inbox. 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 read 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)] SMS_Inbox() +getMsgList(): 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. If they 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 your getValidChoice 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.

Explanation / Answer

1.Firstly, let us see the class SMS_Inbox in java

extends BaseDateTime

class org.cellprofiler.javascript.CPython()

/*The CPython class binds the Python interpreter to the JVM and provides the ability to execute Python scripts.*/

public class SMS_Inbox

{

{

ArrayList<String> getMsgList(List<String> m1,List<String> m2,....List<String> mn)

{

/For reading n messages

Inbox.add(m1);

Inbox.add(m2);

Inbox.add(mn);

}

ArrayList<String> addnewArrival(String senderPhone,DateTime arriveTime,String msgText)

{

/For adding incoming messages to arrivalinbox list

String p=senderPhone ;

DateTime a=arriveTime;

String s=msgText;

arrivalInbox.add(p,a,s);

}

String str()

{

//prints messages in inbox, one per line

System.out.println(" ");

}

}

Integer countMessages()

{

//count messages in inbox

}

return count;

}

}

}

2.We need to create python program for reading the text messages file.

{

def _init_(self):

# init_(self) is the first method called on class creation and this firdt instance is intialised as self

self.msgList=[ ]

def add_New_Arrival(self,senderPhone,arriveTime,msgText):

#this function adds new message with given input parameters in instance

self.msgList.append(False,SenderPhone,arriveTime,msgText)

def countMessages(self):

#this function counts number of messages in message list of inbox

return len(self.msgList)

def str(self)

#this function prints each message in msgList on a new line

print ' '.join( [str(msg) for msg in self.msgList] )

def createMenu(titleofMenu,optionlist):

#this function displays menu to user based on choice 1 to 4

print"Your Option List is: "

print " "

print "1. Send a message "

print "2. Print the inbox "

print "3. Print the number of messages in inbox "

print "4.Quit "

print " "

return input("Choose your option: ")

loop=1

num=getValidChoice()

while loop==1:

choice=createMenu();

if choice==1:

joeInbox.add_New_Arrival()

if choice==2:

joeInbox.getMsgList()

if choice==3

joeInbox.countMessages()

if choice==4:

print 'Quit'

loop=0

def getValidChoice(msg,start,end)

# this function validates the numeric choice entered by the user in the createMenu function

num=input('Enter your choice : ')

while(num>=1 and num<=4)

print "Valid choice"

return num

#intialising the new instance of SMS_Inbox class as joeInbox

joeInbox=SMS_Inbox() //creates new instance of SMS_Inbox class

#Ask user to read messages from data.txt file and add to inbox using add_New _Arrival method

# we append each line of file to the list lines[ ]

with open('data.txt','rt') as file:

for line in file:

lines.append(line)

# storing each item of list line in its variable and calling add_New_Arrival method to add the new message entries in inbox

for i in range(0,len(lines)):

senderPhone=lines[i]

arriveTime=lines[i+1]

msgText=lines[i+2]

joeInbox.add_New_Arrival(False,senderPhone,arriveTime,msgText)

else:

joeInbox.add_New_Arrival(False,'111-222-3333',2017-01-31 14:35:01,'meet me at MSUM')

joeInbox.add_New_Arrival(True,'111-345-3678',2017-01-01 12:30:32,'back at noon')

print "Thanks for using the SMS_Inbox class"