Advertisement
STANAANDREY

classy song

Jul 3rd, 2021
1,259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. package com.company;
  2. import java.util.*;
  3.  
  4. class Song{
  5.     private String title, artist;
  6.     private SortedSet<String> uListeners;
  7.     public Song(String title, String artist) {
  8.         this.title = title;
  9.         this.artist = artist;
  10.         uListeners = new TreeSet<>();
  11.     }
  12.     public String getTitle() {
  13.         return title;
  14.     }
  15.     public String getArtist() {
  16.         return artist;
  17.     }
  18.     public int howMany(ArrayList<String> listeners) {
  19.         int ans = 0;
  20.         for (String listener : listeners) {
  21.             listener = listener.toLowerCase();
  22.             if (!uListeners.contains(listener)) {
  23.                 uListeners.add(listener);
  24.                 ans++;
  25.             }
  26.         }
  27.         return ans;
  28.     }
  29. }
  30.  
  31. public class Main {
  32.     public static void main(String[] args) {
  33.         Song mountMoose = new Song("Mount Moose", "The Snazzy Moose");
  34.         System.out.println(mountMoose.howMany(new ArrayList<String>(Arrays.asList("John", "Fred", "BOb", "carl", "RyAn"))));
  35.         System.out.println(mountMoose.howMany(new ArrayList<String>(Arrays.asList("JoHn", "Luke", "AmAndA"))));
  36.     }
  37. }
  38. //https://www.codewars.com/kata/6089c7992df556001253ba7d
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement