veronikaaa86

04. Songs

Oct 27th, 2021 (edited)
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. package objectAndClasses;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. public class P04Songs {
  8. static class Song {
  9. String typeList;
  10. String name;
  11. String time;
  12.  
  13. Song (String type, String name, String time) {
  14. this.typeList = type;
  15. this.name = name;
  16. this.time = time;
  17. }
  18.  
  19. // public void setTypeList(String typeList) {
  20. // this.typeList = typeList;
  21. // }
  22.  
  23. public String getTypeList() {
  24. return this.typeList;
  25. }
  26.  
  27. // public void setName(String name) {
  28. // this.name = name;
  29. // }
  30.  
  31. public String getName() {
  32. return this.name;
  33. }
  34.  
  35. // public void setTime(String time) {
  36. // this.time = time;
  37. // }
  38.  
  39. public String getTime() {
  40. return this.time;
  41. }
  42. }
  43.  
  44. public static void main(String[] args) {
  45. Scanner scanner = new Scanner(System.in);
  46.  
  47. int n = Integer.parseInt(scanner.nextLine());
  48.  
  49. List<Song> songsList = new ArrayList<>();
  50. for (int i = 0; i < n; i++) {
  51. String[] data = scanner.nextLine().split("_");
  52.  
  53. String type = data[0];
  54. String name = data[1];
  55. String time = data[2];
  56.  
  57. Song currentSong = new Song(type, name, time);
  58.  
  59. // currentSong.setTypeList(type);
  60. // currentSong.setName(name);
  61. // currentSong.setTime(time);
  62.  
  63. songsList.add(currentSong);
  64. }
  65.  
  66. String command = scanner.nextLine();//all typeList
  67.  
  68. if (command.equals("all")) {
  69. for (Song item : songsList) {
  70. System.out.println(item.getName());
  71. }
  72. } else {
  73. for (Song item : songsList) {
  74. if (item.getTypeList().equals(command)) {
  75. System.out.println(item.getName());
  76. }
  77. }
  78. }
  79. }
  80. }
  81.  
Add Comment
Please, Sign In to add comment