Question: Create a class named CellPhone that extends the Phone class, incorporating the functionalities of a CellPhonePlan. This class represents a cellphone that not only has

Create a class named CellPhone that extends the Phone class, incorporating the functionalities of a CellPhonePlan. This class represents a cellphone that not only has basic capabilities like making and receiving calls but also manages its usage based on a cellphone plan. The plan dictates the available minutes and messages, and the phone's actions are contingent upon the remaining allowances in the plan. This class includes an enhanced constructor to accept a CellPhonePlan and additional methods for sending and receiving messages, enforcing the constraints of the plan.
Properties:
phone_number: (Inherited from the parent class) The phone's number, serving as a unique identifier.
battery: A floating-point value between 0 and 1, representing the battery's current charge level. This value must always be between 0 and 1.
plan: The CellPhonePlan associated with this cell phone.
Constructor:
def __init__(self, phone_number:str, plan:'CellPhonePlan'):
"""
Initializes a new CellPhone instance with a specified phone number and an associated cellphone plan.
Args:
phone_number (str): The phone's unique number.
plan (CellPhonePlan): The cellphone plan associated with this phone.
Additional Properties:
- battery (float): Initialized to 1(100%), indicating a full charge at the start.
"""
Override Methods:
def make_call(self, total_time:int, phone_number:str):
"""
Attempts to call a specified number for a specified amount of time, checking the associated plan's available minutes
before proceeding. Calculates the maximum call duration limited by battery life, then passes this duration to the
`receive_call()` method of the receiving phone. The smaller value between total_time and the duration returned by
`receive_call()` is used to deduct from this phone's plan.
For every minute the call lasts, the phone's battery is drained by 0.5%(0.005 of its total charge). If the battery is
depleted, it's at 0, the call cannot be initiated. If there isn't enough battery to sustain the intended duration, the call is
adjusted to match the available battery life, resulting in a shorter call.
Args:
total_time (int): The intended duration of the call in minutes.
phone_number (str): The target phone number to call.
Raises:
RuntimeError: If there are not enough minutes left in the caller's plan, the receiver's plan, or if the phone number is not
in the network.
"""
def receive_call(self, total_time:int)-> int:
"""
Simulates receiving a call, checking the associated plan's available minutes before proceeding.
For every minute the call lasts, the phone's battery is drained by 0.5%(0.005 of its total charge). If the battery reaches 0,
the call cannot be received, and this method returns 0. If there isn't enough battery to complete the call as intended, the
duration is adjusted to match the available battery life, resulting in a shorter call. The actual time the call lasted is
returned if the battery can sustain the call fully.
Args:
total_time (int): The intended duration of the call in minutes.
Returns:
int: The actual duration of the call, which may be less than the intended duration if battery limitations apply.
Raises:
RuntimeError: If there are not enough minutes left in the plan.
"""
New Methods:
def send_message(self, number:str):
"""
Attempts to send a message to a specified number, checking the associated plan's available messages before
proceeding.
For every sent message, the phone's battery is drained by 0.1%(0.001 of its total charge). The message sending
process depletes the battery regardless of message receipt.
Args:
number (str): The phone number to send the message to.
Raises:
RuntimeError: If there are not enough messages left in the plan or if the number is not in the network.
"""
def receive_message(self):
"""
Simulates receiving a message, checking the associated plan's available messages before proceeding.
For every received message, the phone's battery is drained by 0.1%(0.001 of its total charge). If the battery reaches 0,
the message cannot be received.
Raises:
RuntimeError: If there are not enough messages left in the plan.
"""
def charge(self, minutes:int):
"""
Increases the phone's battery charge based on the number of minutes it has been charged, with every 10 minutes restoring 0.1 to the battery charge.
Args:
minutes (int): The number of minutes the phone has been charged.
Note:
- The battery charge cannot exceed 100%(1).
- The battery charge increases by 10%(0.1) for every 10 minutes of charging.
"""
This CellPhone class effectively integrates the functionality of a phone wi

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!