Finad all the area codes and mobile prefixes called by people in bangalore. Fixed lines start with an area code neclosed in parenthesis. The area codes vary in length but always begin with 0. Mobile numbers have no parenthesis, but have a space in the middle of the number to help readability. the prefix of a mobile number is its first four digits and they always tart with 7,8, or 9.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Using java -------------

 

Finad all the area codes and mobile prefixes called by people in bangalore. Fixed lines start with an area code neclosed in parenthesis. The area codes vary in length but always begin with 0. Mobile numbers have no parenthesis, but have a space in the middle of the number to help readability. the prefix of a mobile number is its first four digits and they always tart with 7,8, or 9. 

 

Telemarkets numbers have no parenthese or space, but they start with the area code 140. The return string for outgoingCallsFromBangalore should be all the area codes in lexicographic order with no duplicates.

Expert Solution
Step 1

import csv 
with open('texts.csv', 'r') as f: 
reader = csv.reader(f)
 texts = list(reader) 
with open('calls.csv', 'r') as f: 
reader = csv.reader(f) 
calls = list(reader)
def filter(calls):
 # this function goes through 'calls.txt' and identifies data with the origin from Bangalore. bangalore = list() 
for call in calls: 
if call[0].startswith('(080)'): bangalore.append(call[1]) 
return bangalore
def areacode(bangalore):
 ''' Depending on the type of phone number, add the area code to the list if it is not a duplicate ''' code_list = list()
 for phone_n in bangalore:
 if phone_n.startswith('('):
 end = iter_fixed(phone_n) 
temp = phone_n[0:end+1] 
if temp not in code_list: code_list.append(temp)
 elif phone_n.startswith('7' or '8' or '9'): 
end = iter_mobile(phone_n)
 temp = phone_n[0:end] 
if temp not in code_list: code_list.append(temp) 
else: temp = '140'
 if temp not in code_list: code_list.append(temp)
 return code_list 
def iter_fixed(phone_n): 
# extracting area code for fixed numbers i=0 while phone_n[i] != ")":
 i = i+ 1
 return idef iter_mobile(phone_n): 
# extracting area code for mobile numbers i=0 while phone_n[i] != " ": 
i = i+1
 return i

def printline(): 
# prints codes one for each line. 
# RUNTIME ANALYSIS: The whole program is run in O(n^2log(n)) time because
 # all functions are in O(n) but I run sorted on top of that? -> Question. codes = sorted(areacode(filter(calls)))
 for i in codes: 
print(i)

 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education