Advertisement
veronikaaa86

04. Songs

Feb 22nd, 2023
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 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.         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 getName() {
  20.             return this.name;
  21.         }
  22.  
  23.         public String getTypeList() {
  24.             return this.typeList;
  25.         }
  26.     }
  27.  
  28.     public static void main(String[] args) {
  29.         Scanner scanner = new Scanner(System.in);
  30.  
  31.         int n = Integer.parseInt(scanner.nextLine());
  32.  
  33.         List<Song> songsList = new ArrayList<>();
  34.         for (int i = 1; i <= n; i++) {
  35.             String input = scanner.nextLine();
  36.             String[] inputSongsArr = input.split("_");
  37.             String typeListInput = inputSongsArr[0];
  38.             String nameInput = inputSongsArr[1];
  39.             String timeInput = inputSongsArr[2];
  40.  
  41.             Song currentSong = new Song(typeListInput, nameInput, timeInput);
  42.  
  43.             songsList.add(currentSong);
  44.         }
  45.  
  46.         String command = scanner.nextLine();
  47.         if (command.equals("all")) {
  48.             for (Song song : songsList) {
  49.                 System.out.println(song.getName());
  50.             }
  51.         } else {
  52.             for (Song song : songsList) {
  53.                 String currentTypeList = song.getTypeList();
  54.                 if (currentTypeList.equals(command)) {
  55.                     System.out.println(song.getName());
  56.                 }
  57.             }
  58.         }
  59.     }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement