5.2P.pdf - Swinburne University of Technology 2021 Sem 1 Introduction to Programming Doubtfire Submission Music Records Submitted By Duleen Vinnath

5.2P.pdf - Swinburne University of Technology 2021 Sem 1...

This preview shows page 1 out of 4 pages.

Unformatted text preview: Swinburne University of Technology 2021 Sem 1 Introduction to Programming Doubtfire Submission Music Records Submitted By: Duleen Vinnath Weeraratne 103492480 2021/04/09 13:58 Tutor: Muneeb Ul Hassan April 9, 2021 Produced by Doubtfire File 1 of 2 1 code require './input_functions' 2 3 4 5 module Genre POP, CLASSIC, JAZZ, ROCK = *1..4 end 6 7 8 # Maybe the following needs to be changed? How? $genre_names = ['Null', 'Pop', 'Classic', 'Jazz', 'Rock'] 9 10 11 class Album attr_accessor :title, :artist, :genre 12 13 14 15 16 17 18 def initialize(title, artist, genre) @title = title @artist = artist @genre = genre end end 19 20 21 22 23 # This function Reads in and returns a single album from the given file, with all ,→ its tracks. # ...for now however, take input from the terminal to enter just the album ,→ information. # Complete the missing lines of code and change the functionality so that the ,→ hardcoded # values are not used. 24 25 def read_album() 26 27 28 29 30 # # # # You could use get_integer_range below to get a genre. You only the need validation if reading from the terminal (i.e when using a file later, you can assume the data in the file is correct) 31 32 33 34 35 36 37 38 39 # insert lines here - use read_integer_in_range to get a genre puts("Enter Album") album_title = read_string("Enter album name: ") album_artist = read_string("Enter artist name: ") album_genre = read_integer_in_range("Please enter the genre (1-4): ", 1, 4) album = Album.new(album_title, album_artist, album_genre) return album end 40 41 42 # Takes a single album and prints it to the terminal # complete the missing lines: 43 44 45 46 47 48 49 50 def print_album(album) puts('Album information is: ') # insert lines here puts("Name is" + album.title) puts("Artisit is" + album.artist) puts('Genre is ' + album.genre.to_s) puts($genre_names[album.genre]) Page 1 of 3 File 1 of 2 51 code end 52 53 # Reads in an Album then prints it to the terminal 54 55 56 57 58 def main() album = read_album() print_album(album) end 59 60 main() Page 2 of 3 File 2 of 2 screen shot Page 3 of 3 ...
View Full Document

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture