Question: USE PYTHON3; DO NOT IMPORT DOCTESTS Please read the problem carefully and make sure to solve everything. Thank you! Note: The entire function will initially

USE PYTHON3; DO NOT IMPORT DOCTESTS

Please read the problem carefully and make sure to solve everything. Thank you!

Note: The entire function will initially be commented out in the starter code since we have the ***** placeholders that will cause a syntax error. You can remove the '''s when you are ready to start working on this question.

Create a class called Phone that represents a Phone object. There are 3 instance attributes (properties) passed in when initialized. The brand of the phone (string), its maximum battery capacity (integer representing mAh), and its storage capacity (integer representing MBs).

There are 5 more attributes that you must derive from the instance attributes:

The charge of the phone will be half of its maximum battery capacity (keep charge as an integer, use floor divide //).

The drain_rate represents how much charge the phone uses per minute and will be determined by the phone's brand:

  • 'Apple' will have a drain_rate of 10.

  • 'OnePlus' will have a drain_rate of 12.

  • 'Samsung' will have a drain_rate of 8. All other brands will have a drain_rate of 15.

The charge_rate represents how much the phone charges per minute when charging. The charge_rate will be 20, across all devices.

The num_apps represents how many applications are installed on the device. Out of the box, no apps will be installed.

The apps represent a set (use Pythons set()) of the names of the applications that are installed on the device. Since there are no apps installed out of the box, it will be initialized as an empty set.

After the constructor, you must implement 3 methods.

use(self, minutes) will update the phone's charge based on how many minutes it is used and what the phone's drain_rate is. In the case where we run out of charge, you will return the string 'Out of charge'. You should make sure that the charge is not negative in the case where the charge is drained. In normal use cases, you do not need to return anything.

recharge(self, minutes) will update the phone's charge based on how many minutes it is recharged. In the case where we overcharge, you should make sure that the charge does not exceed the battery's maximum capacity.

install(self, app_size, app_name) will install an app with the given app_name (string) and app_size (integer representing MB). You must consider the following cases before you can install the app.

  1. An app cannot be installed if we have no charge

  2. An app cannot be installed if we do not have sufficient storage. We can install apps up until we have 0MB of storage left

  3. An app cannot be installed if it is already installed. We base this off of the class attribute apps

Once we have dealt with these cases, we can install our app. Make sure that you are updating storage, num_apps, and apps.

class Phone:

"""

Creates a Phone class with 5 class attributes (charge, drain_rate,

charge_rate, num_apps, apps), 3 instance attributes (brand, battery, storage), and 3 methods (use, recharge, install)

>>> my_phone = Phone('Apple', 4000, 64000)

>>> my_phone.brand

'Apple'

>>> my_phone.charge

2000

>>> my_phone.num_apps

0

>>> my_phone.use(10)

>>> my_phone.charge

1900

>>> my_phone.recharge(10)

>>> my_phone.charge

2100

>>> my_phone.install(1000, 'Robinhood')

'App installed'

>>> my_phone.apps

{'Robinhood'}

>>> my_phone.storage

63000

>>> my_phone.use(210)

'Out of charge'

>>> my_phone.recharge(400)

>>> my_phone.charge

4000

"""

# Initializer

def ******(self, brand, ******, ******):

self.brand = brand

self.battery = ******

self.storage = ******

self.charge = ******

# Drain rate will differ based on brand

# Create if-else structure

self.drain_rate = ******

self.charge_rate = ******

self.num_apps = ******

self.apps = ******

def use(self, minutes):

# TODO: Update charge

self.****** = ******

if ******: # Handles case when we run out of charge

******

return 'Out of charge'

def recharge(self, minutes):

# TODO: Update charge

******.****** = ******

def install(self, app_size, app_name):

# Cannot install apps when we don't have charge

if ******:

return 'Out of charge'

# Cannot install apps when we don't have sufficient storage

if ******:

return 'Not enough storage'

# Cannot install apps that are already installed

if ******:

return 'App already installed'

# Have dealt with all potential issues. Install app now

# TODO: Update storage

******

# TODO: Update num_apps

******

# TODO: Update apps

******

return 'App installed'

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 Databases Questions!