peshopbs2

Untitled

Dec 5th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. package program;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6. public class Program {
  7. public static void main(String[] args) {
  8.  
  9. Scanner sc = new Scanner(System.in);
  10. System.out.println("Enter playlist name: ");
  11. String playlistName = sc.nextLine();
  12.  
  13. Playlist playlist = new Playlist(new ArrayList<Song>(), playlistName);
  14. String command = sc.nextLine();
  15. while(command.equals("end")==false) {
  16. switch(command) {
  17. case "addSong":
  18. //get song info from input and add it to playlist
  19. System.out.println("Enter song genre: ");
  20. String genre = sc.nextLine();
  21. System.out.println("Enter song name: ");
  22. String name = sc.nextLine();
  23. System.out.println("Enter song artist: ");
  24. String artist = sc.nextLine();
  25. System.out.println("Enter song duration: ");
  26. String duration = sc.nextLine();
  27.  
  28. Song song = new Song(genre, name, artist, duration);
  29.  
  30. playlist.add(song);
  31. break;
  32. case "printPlaylist":
  33. //print all songs in the playlist
  34. playlist.printPlaylist();
  35. break;
  36. case "removeSong":
  37. //remove a song from the playlist by its number
  38. int removeIndex = Integer.parseInt(sc.nextLine());
  39. try {
  40. Song removeInfo = playlist.remove(removeIndex);
  41. System.out.println("Successfully removed " +
  42. removeInfo.getArtist() + " - " + removeInfo.getName());
  43. }catch(Exception ex) {
  44. System.out.println(ex.getMessage());
  45. }
  46. break;
  47. case "getSong":
  48. //gets song from the playlist by its number
  49. int getIndex = Integer.parseInt(sc.nextLine());
  50. try {
  51. Song songInfo = playlist.get(getIndex);
  52. System.out.println(songInfo);
  53. }catch(Exception ex) {
  54. System.out.println(ex.getMessage());
  55. }
  56. break;
  57. }
  58.  
  59. command = sc.nextLine();
  60. }
  61. }
  62.  
  63. }
Add Comment
Please, Sign In to add comment