Skip to content

Commit a778b38

Browse files
author
l
committed
add new stretch task
1 parent c6a355c commit a778b38

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

‎sprint-5-stretch/README.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Sprint 5 Stretch - Radio Control App
2+
3+
This is part of an app that can be used to control an online radio station
4+
5+
Your task is to:
6+
1. Upgrade everything use dataclasses
7+
1. Observe how the given `__str__` method works, and add one to the other classes
8+
1. When the `__str__` method is called, have it print the duration in formatted mm:ss rather than just seconds
9+
1. Add a new class of `Person` - you can use your imagination what this includes, but it should have at least a string name
10+
1. Turn the fields for _artists_, _host_, and _guest_ into `Person` classes
11+
1. Make a new class `Podcast` that _extends_ the `TalkShow` class, with an extra string field for _sponsor_
12+
1. Finish implementing the class `Playlist`, and set it to takes a generic, e.g. either `Song` or `TalkShow` or `Podcast`
13+
14+
As you implement, make sure to keep checking with mypy and add your own code at the end to test it works correctly

‎sprint-5-stretch/requirements.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mypy

‎sprint-5-stretch/stretch-radio.py‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
class Song:
2+
def __init__(self, artist, duration, title):
3+
self.artist = artist # should be a string
4+
self.duration = duration # should be an integer in seconds
5+
self.title = title # should be a string
6+
7+
def __str__(self):
8+
return f"{self.artist} - {self.title} ({self.duration})"
9+
10+
class TalkShow:
11+
def __init__(self, host, guests, duration, title):
12+
self.host = host # should be a string
13+
self.guests = guests # should be a list of strings
14+
self.duration = duration # should be an integer in seconds
15+
self.title = title # should be a string
16+
17+
class Playlist:
18+
def __init__(self, items):
19+
self.items = items # A list of Song or TalkShow
20+
self.currently_playing_index = 0
21+
22+
def play_next(self):
23+
pass
24+
# TODO: increment the currently_playing_index, when you get to the end loop back to 0
25+
26+
def get_currently_playing(self):
27+
return "todo"
28+
# TODO: return a string representation of whatever is playing at the current index
29+
# See the __str__ method in Song for an example of how to make a string representation of a class
30+
31+
def get_total_duration(self):
32+
return 0
33+
# TODO: return
34+
35+
song_a = Song("Rick Astley", 210, "Never Gonna Give You Up")
36+
print(song_a)
37+
38+
song_b = Song("Psy", 219, "Gangnam Style")
39+
funny_songs = Playlist([song_a, song_b])
40+
print(funny_songs.get_currently_playing())
41+
42+
show_a = TalkShow("Melvyn Bragg", ["Jim Al-Khalili", "Sheila Rowan", "Carolin Crawford"], 2700, "Gravitational Waves")
43+

0 commit comments

Comments
 (0)