Copy of Project 3 - RetrieverBell.pdf Copy of Project 3 - RetrieverBell - Google Docs

1 answer below »
My task involves creating some sort of phone network. I need it done by next Wednesday. I have given a PDF file containing the instructions, the rubric, the outputs, and what code is allowed and not allowed. Please pay close attention to what is allowed and not allowed. I have also given the files which contain the starter code. This project is based on class solutions. I need there to be comments on all of the files as well. Thank you!


Copy of Project 3 - RetrieverBell.pdf Copy of Project 3 - RetrieverBell - Google Docs
Answered Same DayNov 25, 2021

Answer To: Copy of Project 3 - RetrieverBell.pdf Copy of Project 3 - RetrieverBell - Google Docs

Prasun Kumar answered on Dec 02 2021
153 Votes
sancia/.idea/.gitignore
# Default ignored files
/shelf/
/workspace.xml
sancia/.idea/inspectionProfiles/profiles_settings.xml





sancia/.idea/misc.xml


sancia/.idea/modules.xml






sancia/.idea/sancia.iml









sancia/.idea/workspace.xml










































































1606555179926


1606555179926





























sancia/commands.txt
switch-add 443
switch-add 410
switch-add 656
display
switch-connect 443 410
phone-add 656-112-3412
phone-add 443-132-1332
display
start-call 656-112-3412 443-132-1332
switch-connect 656 410
start-call 656-112-3412 443-132-1332
display
network-save sample1.net
quit
network-load test.net
display
start-call 223-1231234 410-223-3333
start-call 410-223-3333 310-555-5555
start-call 310-222-2222 310-111-1111
display
end-call 310-111-1111
end-call 545-123-1234
end-call 410-555-5555
display
quit
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Do not run the code below                 %
% It is to show how test.net was created    %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
switch-add 310
switch-add 410
switch-connect 310 410
phone-add 310-222-2222
phone-add 310-555-5555
phone-add 310-111-1111
phone-add 310-123-1233
switch-add 443
switch-connect 410 443
phone-add 410-223-3333
phone-add 410-345-3456
phone-add 443-910-9191
switch-add 545
phone-add 545-123-1234
switch-add 223
phone-add 223-123-1234
network-save test.net
sancia/network.py
"""
network.py is both the definition file for the Network class
as well as the driver for the program.
In network you need to implement the functions which the driver
will call for the all the different commands.
Author: Sancia
Date: Dec 02, 2020
"""
from phone import Phone
from switchboard import Switchboard
# the soltuion does not use any external library (json or csv)
# Some constants below are for the driver, don't remove them unless you mean to.
HYPHEN = "-"
QUIT = 'quit'
SWITCH_CONNECT = 'switch-connect'
SWITCH_ADD = 'switch-add'
PHONE_ADD = 'phone-add'
NETWORK_SAVE = 'network-save'
NETWORK_LOAD = 'network-load'
START_CALL = 'start-call'
END_CALL = 'end-call'
DISPLAY = 'display'
class Network:
"""
Defines the basic network class
1 parameters (1) list of switch boards
9 functions (1) get_switchboard_from_areacode
(2) load_network
(3) save_network
(4) add_switchboard
(5) connect_switchboards
(6) display
(7) make_a_call
(8) disconnect_a_call
"""
def __init__(self):
"""
Construct a network by creating the switchboard container object
You are free to create any additional data/members necessary to maintain this class.
"""
self.switch_boards = []
def get_switchboard_from_areacode(self, code):
"""
Function to get the switchboard object based on its area code
:param code: area code we are looking for
:return: Switchboard object
"""
for each_switch_board in self.switch_boards:
if each_switch_board.area_code == code:
return each_switch_board
def load_network(self, filename):
"""
:param filename: the name of the file to be loaded.
Assume it exists and is in the right format.
If not, it's ok if your program fails.
:return: None
"""
self.switch_boards = [] #garbage collection can be improved
with open(filename, 'r') as reader:
number_of_switchboards = int(reader.readline().strip())
for i in range(number_of_switchboards):
area_code = int(reader.readline().strip())
sB = Switchboard(area_code)
number_of_phones = int(reader.readline().strip())
for j in range(number_of_phones):
number = int(reader.readline().strip())
aCode = int(reader.readline().strip())
sB.phones.append(Phone(number, aCode))
self.switch_boards.append(sB)
for i in range(number_of_switchboards):
lTrunk = reader.readline().strip()
if not lTrunk == 'None':
self.switch_boards[i].trunk_left = \
self.get_switchboard_from_areacode(int(lTrunk))
rTrunk = reader.readline().strip()
if not rTrunk == 'None':
self.switch_boards[i].trunk_right = \
self.get_switchboard_from_areacode(int(rTrunk))
def save_network(self, filename):
"""
:param filename: the name of your file to save the network.
Remember that you need to save all the
connections, but not the active phone calls
(they can be forgotten between save and load).
The format of the file used is (one per line):
- number of switchboards
- area code of each
- number of phones in each
- phone number of each
- both trunks of each switchboard
:return: None
"""
with open(filename, 'w') as f:
f.write(str(len(self.switch_boards))+'\n')
for each_switch_board in self.switch_boards:
f.write(str(each_switch_board.area_code)+'\n')
f.write(str(len(each_switch_board.phones))+'\n')
for eachPhone in each_switch_board.phones:
f.write(str(eachPhone.number)+'\n')
f.write(str(eachPhone.switchboard)+'\n')
for each_switch_board in self.switch_boards:
if each_switch_board.trunk_left == None:
f.write('None\n')
else:
f.write(str(each_switch_board.trunk_left.area_code)+'\n')
if each_switch_board.trunk_right == None:
f.write('None\n')
else:
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here