In: Computer Science
Basic Pass Level Requirements - 53
Your extended Text Based Music Application must add the following functionality:
Display a menu that offers the user the following options:
1. Read in Albums
2. Display Albums
3. Select an Album to play
4. Update an existing Album
5. Exit the application
Menu option 1 should prompt the user to enter a filename of a file that contains the following information:
·The number of albums
·The first album name
·The first artist name
·The genre of the album
·The number of tracks (up to a maximum of 15)
·The name and file location (path) of each track.
·The album information for the remaining albums.
Menu option 2 should allow the user to either display all albums or all albums for a particular genre. The albums should be listed with a unique album number which can be used in Option 3 to select an album to play. The album number should serve the role of a ‘primary key’ for locating an album. But it is allocated internally by your program, not by the user.
Menu option 3 should prompt the user to enter the primary key (or album number) for an album as listed using Menu option 2.If the album is found the program should list all the tracks for the album, along with track numbers. The user should then be prompted to enter a track number. If the track number exists, then the system should display the message “Playing track ” then the track name, “ from album ” then the album name. You may or may not call an external program to play the track, but if not the system should delay for several seconds before returning to the main menu.
Menu option 4 should allow the user to enter a unique album number and change its title or genre. The updated album should then be displayed to the user and the user prompted to press enter to return to the main menu (you do not need to update the file at this level)..
At this level minimum validation is required. Just make sure your program does not crash if incorrect values are entered and that all fields have an expected value (eg: perhaps have a default genre of “unknown” in case the user enters and incorrect value for genre
input function :
# Display the prompt and return the read string
def read_string prompt
puts prompt
value = gets.chomp
end
# Display the prompt and return the read float
def read_float prompt
value = read_string(prompt)
value.to_f
end
#takes a number only decimal or intger
def read_float_only prompt
puts(prompt)
value=Float(gets) rescue nil
while(value == nil)
puts('Please enter a real number:
')
value=Float(gets) rescue nil
end
value.to_f
end
# Display the prompt and return the read integer
def read_integer prompt
value = read_string(prompt)
value.to_i
end
# takes intgers only
def read_integer_only prompt
puts(prompt)
value=Integer(gets) rescue nil
while(value == nil)
puts('Please enter a real number:
')
value=Integer(gets) rescue
nil
end
value.to_i
end
# Read an integer between min and max, prompting with
the string provided
def read_integer_in_range(prompt, min, max)
value = read_integer(prompt)
while (value < min or value > max)
puts "Please enter a value between
" + min.to_s + " and " + max.to_s + ": "
value = read_integer(prompt);
end
value
end
# Display the prompt and return the read Boolean
def read_boolean prompt
value = read_string(prompt)
case value
when 'y', 'yes', 'Yes', 'YES'
true
else
false
end
end
#Test the functions above
#def main()
#value=read_float_only("please enter a number:")
#end
#main()
what do u mean u need more example
use RUBY program.
what other information do u need?
Here the answer for the given information written in ruby program
module Genre
POP, CLASSIC, JAZZ, ROCK = *1..4 //here is the music genre
names
end
$genre_names = ['Null','Pop', 'Classic', 'Jazz', 'Rock']//genre
names are taken in a string format
class Track
attr_accessor :name, :location
def initialize (name, location)
@name = name //name of the album
@location = location //location of the album
end
end
class Albums
attr_accessor :title, :artist, :genre, :tracks, :length
def initialize (title, artist, genre, tracks)
@title = title
@artist = artist
@genre = genre
@tracks = tracks
@length = length
end
end
def read_track
name = read_string('please enter track name') //it enters the track
name
puts 'you have entred ' + name.to_s + ' as track name'
location = read_string('please enter track file location') //it
enters the file location
puts 'you have entred ' + location.to_s + ' as location'
track = Track.new(name,location)
return track
end
def read_tracks
tracks = Array.new()
count = read_integer_in_range("Enter how many tracks in album : ",
0, 100) //Asking how many tracks in a album
puts 'you have entred ' + count.to_s + ' tracks as album tracks'
//it enters the tracks in a string format
index = 0
while (index < count)
track = read_track
tracks << track
index +=1
end
return tracks
end
def read_genre //taking the input
index = 0
length = $genre_names.length - 1
num = 1
puts "\n"'please selecet album genre from the list below'
while (index < length)
puts "#{index + 1 } " +'-'+ $genre_names[index+1].to_s
index +=1
num +=1
end
num = 1
album_genre = read_integer_in_range("enter genre: ", 1, 4)
puts 'you have entred ' + $genre_names[album_genre] + ' as album
genre'
num +=1
return album_genre
end
def read_albums albums
count = read_integer("\n"'please enter how many how many albums you
want to add to the music player? ')
puts "\n" 'you have entred ' + count.to_s + ' albums to be added to
the music player'
albums = Array.new
index = 0
while (index < count)
albums << read_album
index +=1
end
return albums
end
def read_album
puts
album_title = read_string('please enter album title')
puts 'you have entred ' + album_title.to_s + ' as album
title'
album_artist = read_string('please enter album artisit')
puts 'you have entred ' + album_artist.to_s + ' as album
artist'
album_genre = read_genre
tracks = read_tracks
album = Albums.new(album_title, album_artist, album_genre,
tracks)
return album
end
def print_tracks tracks
index = 0
num = 1
puts 'YOU HAVE ENTRED ' + tracks.length.to_s + ' TRACKS
INFORMATION'
while (index < tracks.length)
puts 'TRACK ' + num.to_s + ''
puts'Track Title Is: ' + tracks[index].name
puts'Track File Location Is: ' + tracks[index].location
index += 1
num +=1
end
end
def print_albums albums
puts
puts 'YOU HAVE ENTRED ' + albums.length.to_s + ' ALBUMS
INFORMATION'
puts
index = 0
num = 1
while (index < albums.length)
puts 'Album ' + num.to_s + ' information : '
puts "Album Artist : " + albums[index].artist
puts "Album Title : " + albums[index].title
puts 'Album Genre: ' + $genre_names[albums[index].genre]
print_tracks(albums[index].tracks)
puts
index +=1
num +=1
end
end
def main
finished = false
puts "Welcome to the music player"
begin
puts 'Main Menu:'
puts '1 - Read in Albums'
puts '2 - Display Albums'
puts '3 - Select an Album to play'
puts '4 - Update an existing Album'
puts '5 - Exit the application'
inter = read_integer_in_range("Please enter your choice:", 1,2,3,4,
5)
case inter
when 1
albums = read_albums(albums)
when 2
print_albums(albums)
when 3
print($genre_names.select{Null','Pop', 'Classic', 'Jazz',
'Rock'})
when 5
puts 'EXITING, GOODBYE'
finished = true
end
end until finished
end
main
//End of the program
//It take all the inputs and print the given format