-
Notifications
You must be signed in to change notification settings - Fork 0
/
OOP.py
100 lines (65 loc) · 2.22 KB
/
OOP.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def get_date_today():
return (2013, 10, 30)
class Artist(object):
def __init__(self, name, dob):
self.name=name
self.dob=dob
def age(self):
dob=self.dob
today=get_date_today()
delta_year=today[0]-dob[0]
if today[1]>dob[1] or (today[1]==dob[1] and today[2]>dob[2]):
return delta_year
else:
return delta_year-1
def get_name(self):
return self.name
def get_dob(self):
return self.dob
class Duration(object):
def __init__(self, minutes, seconds):
self.minutes=minutes
self.seconds=seconds
self.total_seconds=minutes*60+seconds
def __str__(self):
if len(str(self.get_minutes()))==1:
minstr='0'+str(self.get_minutes())
else:
minstr=self.get_minutes()
if len(str(self.get_seconds()))==1:
secstr='0'+str(self.get_seconds())
else:
secstr=self.get_seconds()
return str(minstr)+":"+str(secstr)
def __add__(self,object):
return Duration(self.get_minutes()+object.get_minutes(),self.get_seconds()+object.get_seconds())
def get_minutes(self):
return self.total_seconds//60
def get_seconds(self):
return self.total_seconds%60
class Song(object):
def __init__(self, artist, title, duration):
self.artist=artist
self.title=title
self.duration=duration
def get_artist(self):
return self.artist
def get_title(self):
return self.title
def get_duration(self):
return self.duration
class Album(object):
def __init__(self, artist, title):
self.artist=artist
self.title=title
self.collection=[]
def add_song(self, song):
self.collection.append(song)
def total_runtime(self):
if self.collection==[]:
return Duration(0,0)
else:
result=Duration(0,0)
for song in self.collection:
result+=song.get_duration()
return result