Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

start from def add_call(self, call) * Don't import anything, and you can use all built-ins/methods that are otherwise available. * adding definitions: You may add

image text in transcribedimage text in transcribedimage text in transcribed

start from def add_call(self, call)

* Don't import anything, and you can use all built-ins/methods that are otherwise available. * adding definitions: You may add additional methods and functions in support of your solution. * displaying things: _str__and_ _repr_are used by many other places in Python to get a string representation of the object. Specifically, str() calls__str_, and repr() calls_repr__, on any objects they receive as arguments. _str__often generates a human-centric representation, appropriate for a human reading what is present.__repr_often generates a Python-centric representation. The goal of_repr__is actually to have a string that could be evaluated to re-generate an identical object. In general, we would quite prefer it to look like a valid constructor call, if possible. Ultimately, we can have the same representation in str _ and repr_ if we'd like; in fact, when we didn't explicitly describe two different string representations for_str__and__repr_ to return, we can define one in terms of the other, like this def _repr_(self): return str(self) Just remember the original intent of-st-vs-rep-. It's good practice to define-init- and_repr_immediately before writing any extra methods in a Python class at a minimum, and perhaps also eq_as well. str class PhonePlan: definit_(self, type, lines None): create/initialize instance variables for type and the list of lines in the plan. When lines is not provided, use an empty list as its initial value. Create an instance variable calls to keep a list of calls made/received by any line of this plan, initialize it to be an empty list. Also create instance variables for balance, rollover_mins, and mins_to_pay, all starting at zero defstr_(self): create/return a string similar to: "PhonePlan (PlanType (25.50,_200,_0.50, True),[],_[])" See test cases for more examples. Hint: when obtaining strings for the lists of lines/calls, how can you rely upon other str or repr definitions to make this a short/trivial method to write? defrepr__(self): create/return a string identical to the__str_output def activate_all (self): make sure every line in this plan is active after calling this method. def deactivate_all(self): make sure every line in this plan is inactive after calling this method. def activate_all (self): make sure every line in this plan is active after calling this method. def deactivate_all(self): make sure every line in this plan is inactive after calling this method. def add_call(self, cal1): add the given call to the end of the list of calls. Either caller or callee of the given call should be a line of this plan, otherwise do not append but raise a PhonePlanError with error message "call_cannot_be_added". If call can be added, check whether the call is billable based on the ollowing rules: A local call is free and not billable; Hint: use your Call class's is_local method to help. A call made between two lines of this plan is free and not billable o o For a billable call, increment instance variable mins_to_pay based on the length of the call. All updates made in this method change instance variables directly and the method returns None def remove_call(self, call): remove the given call from the list of calls and returns None. If call is not present in the list, raise a PhonePlanError with error message "no_such_call to_remove". def add_calls (self, calls): accept a list of calls, use add_call() to add each to the end of the list of calls and update mins_to_pay accordingly. Count and return the number of calls that are successfully added into the call record. Requirement and Hint: you must call add_call; exception handling can help def make_call(self, caller, callee, length): create a call based on caller, callee, and length, then add it to the end of the list of calls and update mins_to_pay accordingly. Return True if the call is created and added successfully; return False if The call cannot be created due to a CallError; or The call cannot be added due to a PhonePlanError (neither caller nor callee belongs to this o o an * Don't import anything, and you can use all built-ins/methods that are otherwise available. * adding definitions: You may add additional methods and functions in support of your solution. * displaying things: _str__and_ _repr_are used by many other places in Python to get a string representation of the object. Specifically, str() calls__str_, and repr() calls_repr__, on any objects they receive as arguments. _str__often generates a human-centric representation, appropriate for a human reading what is present.__repr_often generates a Python-centric representation. The goal of_repr__is actually to have a string that could be evaluated to re-generate an identical object. In general, we would quite prefer it to look like a valid constructor call, if possible. Ultimately, we can have the same representation in str _ and repr_ if we'd like; in fact, when we didn't explicitly describe two different string representations for_str__and__repr_ to return, we can define one in terms of the other, like this def _repr_(self): return str(self) Just remember the original intent of-st-vs-rep-. It's good practice to define-init- and_repr_immediately before writing any extra methods in a Python class at a minimum, and perhaps also eq_as well. str class PhonePlan: definit_(self, type, lines None): create/initialize instance variables for type and the list of lines in the plan. When lines is not provided, use an empty list as its initial value. Create an instance variable calls to keep a list of calls made/received by any line of this plan, initialize it to be an empty list. Also create instance variables for balance, rollover_mins, and mins_to_pay, all starting at zero defstr_(self): create/return a string similar to: "PhonePlan (PlanType (25.50,_200,_0.50, True),[],_[])" See test cases for more examples. Hint: when obtaining strings for the lists of lines/calls, how can you rely upon other str or repr definitions to make this a short/trivial method to write? defrepr__(self): create/return a string identical to the__str_output def activate_all (self): make sure every line in this plan is active after calling this method. def deactivate_all(self): make sure every line in this plan is inactive after calling this method. def activate_all (self): make sure every line in this plan is active after calling this method. def deactivate_all(self): make sure every line in this plan is inactive after calling this method. def add_call(self, cal1): add the given call to the end of the list of calls. Either caller or callee of the given call should be a line of this plan, otherwise do not append but raise a PhonePlanError with error message "call_cannot_be_added". If call can be added, check whether the call is billable based on the ollowing rules: A local call is free and not billable; Hint: use your Call class's is_local method to help. A call made between two lines of this plan is free and not billable o o For a billable call, increment instance variable mins_to_pay based on the length of the call. All updates made in this method change instance variables directly and the method returns None def remove_call(self, call): remove the given call from the list of calls and returns None. If call is not present in the list, raise a PhonePlanError with error message "no_such_call to_remove". def add_calls (self, calls): accept a list of calls, use add_call() to add each to the end of the list of calls and update mins_to_pay accordingly. Count and return the number of calls that are successfully added into the call record. Requirement and Hint: you must call add_call; exception handling can help def make_call(self, caller, callee, length): create a call based on caller, callee, and length, then add it to the end of the list of calls and update mins_to_pay accordingly. Return True if the call is created and added successfully; return False if The call cannot be created due to a CallError; or The call cannot be added due to a PhonePlanError (neither caller nor callee belongs to this o o an

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago