6.2 P Album File Handling Your application must read the album and…

Question Answered step-by-step 6.2 P Album File Handling Your application must read the album and… 6.2 P ?? Album File HandlingYour application must read the album and track information from the provided album.txt file. Use the provided code album_file_handling.rb as a basis for your program.The output of your program should look as follows: Image transcription textMacBook-Pro-8:6. 17 Album File Handling (updated pdf) mitchells ruby music record answers.rb Neil DiamondGreatest Hits Genre 18 1 POO Crackling Rope sounds/01-Cracklin-ross . Way Soolainon sounds/de-Soolsimon. way Sweet Caroline sounds/20-Sweet_Caroline . way MacBook-Pro-8:4. IT Album File Handling … Show more… Show morealbum_file_handling:module Genre POP, CLASSIC, JAZZ, ROCK = *1..4end$genre_names = [‘Null’, ‘Pop’, ‘Classic’, ‘Jazz’, ‘Rock’]class Album# NB: you will need to add tracks to the following and the initialize()   attr_accessor :title, :artist, :genre, :tracks# complete the missing code:   def initialize (title, artist, genre, tracks)       # insert lines here       @title = title       @artist = artist       @genre = genre       @tracks = tracks         endendclass Track   attr_accessor :name, :location   def initialize (name, location)       @name = name       @location = location   endend# Reads in and returns a single track from the given filedef read_track(music_file)   # fill in the missing code   track_name = music_file.gets.chomp   track_location = music_file.gets.chomp   track = track.new(track_name, track_location)   return trackend# Returns an array of tracks read from the given filedef read_tracks(music_file)     count = music_file.gets().to_i()     tracks = Array.new() # Put a while loop here which increments an index to read the tracks     i = 0     while i < count     track = read_track(music_file)     tracks << track       i+=1      end   return tracksend# Takes an array of tracks and prints them to the terminaldef print_tracks(tracks)   # print all the tracks use: tracks[x] to access each track.   i = 0   while i < tracks.length     print_track(tracks[i])     i+=1   endend# Reads in and returns a single album from the given file, with all its tracksdef read_album(music_file) # read in all the Album's fields/attributes including all the tracks # complete the missing code   album_title = music_file.gets.chomp   album_artist = music_file.gets   album_genre = music_file.gets.to_i   album_tracks = read_tracks(music_file)   album = Album.new(album_title, album_artist, album_genre, album_tracks)   return albumend# Takes a single album and prints it to the terminal along with all its tracksdef print_album(album) # print out all the albums fields/attributes # Complete the missing code.   printf(album.title)   printf("n%s",album.artist)   puts('Genre is ' + album.genre.to_s)   puts($genre_names[album.genre])   # print out the tracksprint_tracks(album_tracks)end# Takes a single track and prints it to the terminaldef print_track(track)     puts('Track title is: ' + track.title)   puts('Track file location is: ' + track.file_location)end# Reads in an album from a file and then print the album to the terminaldef main()   music_file = File.new("album.txt", "r")   album = read_album(music_file)   music_file.close()   print_album(album)endmain()module Genre POP, CLASSIC, JAZZ, ROCK = *1..4end$genre_names = ['Null', 'Pop', 'Classic', 'Jazz', 'Rock']class Album# NB: you will need to add tracks to the following and the initialize()   attr_accessor :title, :artist, :genre, :tracks# complete the missing code:   def initialize (title, artist, genre, tracks)       # insert lines here       @title = title       @artist = artist       @genre = genre       @tracks = tracks         endendclass Track   attr_accessor :name, :location   def initialize (name, location)       @name = name       @location = location   endend# Reads in and returns a single track from the given filedef read_track(music_file)   # fill in the missing code   track_name = music_file.gets.chomp   track_location = music_file.gets.chomp   track = track.new(track_name, track_location)   return trackend# Returns an array of tracks read from the given filedef read_tracks(music_file)     count = music_file.gets().to_i()     tracks = Array.new() # Put a while loop here which increments an index to read the tracks     i = 0     while i < count     track = read_track(music_file)     tracks << track       i+=1      end   return tracksend# Takes an array of tracks and prints them to the terminaldef print_tracks(tracks)   # print all the tracks use: tracks[x] to access each track.   i = 0   while i < tracks.length     print_track(tracks[i])     i+=1   endend# Reads in and returns a single album from the given file, with all its tracksdef read_album(music_file) # read in all the Album's fields/attributes including all the tracks # complete the missing code   album_title = music_file.gets.chomp   album_artist = music_file.gets   album_genre = music_file.gets.to_i   album_tracks = read_tracks(music_file)   album = Album.new(album_title, album_artist, album_genre, album_tracks)   return albumend# Takes a single album and prints it to the terminal along with all its tracksdef print_album(album) # print out all the albums fields/attributes # Complete the missing code.   printf(album.title)   printf("n%s",album.artist)   puts('Genre is ' + album.genre.to_s)   puts($genre_names[album.genre])   # print out the tracksprint_tracks(album_tracks)end# Takes a single track and prints it to the terminaldef print_track(track)     puts('Track title is: ' + track.title)   puts('Track file location is: ' + track.file_location)end# Reads in an album from a file and then print the album to the terminaldef main()   music_file = File.new("album.txt", "r")   album = read_album(music_file)   music_file.close()   print_album(album)endmain()album.txt:Neil DiamondGreatest Hits13Crackling Rosesounds/01-Cracklin-rose.wavSoolaimonsounds/06-Soolaimon.wavSweet Carolinesounds/20-Sweet_Caroline.wav Engineering & Technology Computer Science CS COS10009 Share QuestionEmailCopy link Comments (0)