Advertisement
veronikaaa86

04. Songs

Oct 26th, 2022
1,105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. package classes;
  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.         private String typeList;
  10.         private String name;
  11.         private String time;
  12.  
  13.         public Song(String typeList, String name, String time) {
  14.             this.typeList = typeList;
  15.             this.name = name;
  16.             this.time = time;
  17.         }
  18.  
  19.         public String getTypeList() {
  20.             return this.typeList;
  21.         }
  22.  
  23.         public String getName() {
  24.             return this.name;
  25.         }
  26.  
  27.         public String getTime() {
  28.             return this.time;
  29.         }
  30.     }
  31.  
  32.     public static void main(String[] args) {
  33.         Scanner scanner = new Scanner(System.in);
  34.  
  35.         int n = Integer.parseInt(scanner.nextLine());
  36.  
  37.         List<Song> listSongs = new ArrayList<>();
  38.         for (int i = 0; i < n; i++) {
  39.             String inputLine = scanner.nextLine();
  40.             String[] inputSongArr = inputLine.split("_");
  41.  
  42.             Song currentSong = new Song(inputSongArr[0], inputSongArr[1], inputSongArr[2]);
  43.  
  44.             listSongs.add(currentSong);
  45.         }
  46.  
  47.         String command = scanner.nextLine();
  48.         if (command.equals("all")) {
  49.             for (Song item : listSongs) {
  50.                 System.out.println(item.getName());
  51.             }
  52.         } else {
  53.             for (Song item : listSongs) {
  54.                 if (item.getTypeList().equals(command)) {
  55.                     System.out.println(item.getName());
  56.                 }
  57.             }
  58.         }
  59.  
  60.     }
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement