Senior
# Complication # We have a new product feature: reserving money through a mobile app. # For this, we need to add a new method reserve(amount) to the ATM class. Also, we should consider HardwareError in SDK methods.
sobes.tech AI
Answer from AI
To add new functionality for reserving money in the ATM class, you need to:
- Add a method
reserve(amount)that interacts with the SDK to lock the amount. - Handle the possible
HardwareErrorexception in SDK methods to respond correctly to hardware errors.
Example in Python:
class HardwareError(Exception):
pass
class ATM:
def __init__(self, sdk):
self.sdk = sdk
def reserve(self, amount):
try:
self.sdk.block_amount(amount)
except HardwareError as e:
# Log the error, notify the user, or take recovery actions
print(f"Hardware error during reservation: {e}")
raise
def withdraw(self, amount):
try:
self.sdk.dispense_cash(amount)
except HardwareError as e:
print(f"Hardware error during cash dispensing: {e}")
raise
Thus, the new reserve method adds reservation functionality, and handling HardwareError allows reliable operation with hardware failures.