Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package program;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Program {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter playlist name: ");
- String playlistName = sc.nextLine();
- Playlist playlist = new Playlist(new ArrayList<Song>(), playlistName);
- String command = sc.nextLine();
- while(command.equals("end")==false) {
- switch(command) {
- case "addSong":
- //get song info from input and add it to playlist
- System.out.println("Enter song genre: ");
- String genre = sc.nextLine();
- System.out.println("Enter song name: ");
- String name = sc.nextLine();
- System.out.println("Enter song artist: ");
- String artist = sc.nextLine();
- System.out.println("Enter song duration: ");
- String duration = sc.nextLine();
- Song song = new Song(genre, name, artist, duration);
- playlist.add(song);
- break;
- case "printPlaylist":
- //print all songs in the playlist
- playlist.printPlaylist();
- break;
- case "removeSong":
- //remove a song from the playlist by its number
- int removeIndex = Integer.parseInt(sc.nextLine());
- try {
- Song removeInfo = playlist.remove(removeIndex);
- System.out.println("Successfully removed " +
- removeInfo.getArtist() + " - " + removeInfo.getName());
- }catch(Exception ex) {
- System.out.println(ex.getMessage());
- }
- break;
- case "getSong":
- //gets song from the playlist by its number
- int getIndex = Integer.parseInt(sc.nextLine());
- try {
- Song songInfo = playlist.get(getIndex);
- System.out.println(songInfo);
- }catch(Exception ex) {
- System.out.println(ex.getMessage());
- }
- break;
- }
- command = sc.nextLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment