In: Computer Science
Design a class that holds the following data regarding a music album: artist, title, number of tracks, and year released. Write appropriate accessor and mutator methods. Also, write a program that creates three instances of the class. Each instance will hold information about a different music album. Make sure to display all of the information for all three albums to the screen in an organized manner.
**Using python**
Program:
class Album:
def __init__(self,artist,title,numTracks,year):
self.artist=artist
self.title=title
self.numTracks=numTracks
self.year=year
def setArtist(self,artist):
this.artist=artist
def setTitle(self,title):
this.title=title
def setNumTracks(self,numTracks):
this.numTracks=numTracks
def setYear(self,year):
self.year=year
def getArtist(self):
return
self.artist
def getTitle(self):
return self.title
def getNumTracks(self):
return self.numTracks
def getYear(self):
return self.year
album1=Album("Enrique","Slim Shady",10,1997)
album2=Album("JLegend","GetLifted",8,2004)
album3=Album("Adele","TwentyFive(25)",12,2015)
print("\nArtist\tTitle\t\tNumber of tracks\tYear");
print("----------------------------------------------------------")
print(album1.getArtist(),end="\t")
print(album1.getTitle(),end="\t")
print(album1.getNumTracks(),end="\t\t\t")
print(album1.getYear(),end="\n")
print(album2.getArtist(),end="\t")
print(album2.getTitle(),end="\t")
print(album2.getNumTracks(),end="\t\t\t")
print(album2.getYear(),end="\n")
print(album3.getArtist(),end="\t")
print(album3.getTitle(),end="\t")
print(album3.getNumTracks(),end="\t\t\t")
print(album3.getYear(),end="\n\n")
Program Screenshot:
Output: