|
| 1 | +### Optional Assignment |
| 2 | + |
| 3 | +Below, we want to build up some classes from scratch. We'll describe the attributes and methods that each class should have available, and ask that you come up with the classes. |
| 4 | + |
| 5 | +#### 1. Let's build a `Company` class, used to represent some company (Riyadh Tea Co., Chick Fil A, Chipotle, etc.). |
| 6 | + |
| 7 | +A. In this class, we'll have the following attributes: |
| 8 | + |
| 9 | + * `name` - `str` holding the name of the company |
| 10 | + * `industry_type` - `str` holding what industry the company belongs to |
| 11 | + * `num_employees` - `int` holding the number of employees the company has |
| 12 | + * `total_revenue` - `float` holding the total revenue of the company |
| 13 | + |
| 14 | +B. Instances of the `Company` class will have the following methods: |
| 15 | + |
| 16 | + * `serve_customer` - this method will take in a `float` that is equal to the cost of serving some customer, and then adjust the `total_revenue` by that cost. |
| 17 | + * `gain_employees` - this method will take in a `list` that contains new employees that the company has just brought on, and will update the `num_employees` attribute to take account of that. |
| 18 | + |
| 19 | +#### 2. Let's build a `TV` class, used to represent a television. |
| 20 | + |
| 21 | +A. In this class, we'll have the following attributes: |
| 22 | + |
| 23 | + * `brand` - `str` holding the brand of the television ('Sony', 'LG', etc.) |
| 24 | + * `on_status` - `bool` holding whether or not the television is on. This should default to False (e.g. off). |
| 25 | + * `current_channel` - `int` holding the current channel number. If the television is off, then the `current_channel` should be 0. Given that `on_status` defaults to off, what does that mean the `current_channel` should default to? |
| 26 | + * `life_perc` - `float` holding the percentage of life left in the TV. This should start out at 100% (i.e. default to 100). |
| 27 | + |
| 28 | +B. Instances of the `TV` class will have the following methods: |
| 29 | + |
| 30 | + * `hit_power` - this will turn the television on/off, depending on whether it's already on/off (if its on it'll switch it off, and vice versa). We'll add a couple of stipulations with this one: |
| 31 | + * Each time the television is turned off, it loses a little bit of life - decrease the `life_perc` by 0.01 each time the television is turned off. |
| 32 | + * Each time the television is turned off the channel should be set to 0. |
| 33 | + * `change_channel` - this will take in an `int` to change the channel to a new one. We'll add a stipulation to this as well: |
| 34 | + * If the television is not on, but the `change_channel` method is called, print 'Television is not on!'. Otherwise, change the channel to the inputted channel. |
0 commit comments