Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- class Song{
- private String title, artist;
- private SortedSet<String> uListeners;
- public Song(String title, String artist) {
- this.title = title;
- this.artist = artist;
- uListeners = new TreeSet<>();
- }
- public String getTitle() {
- return title;
- }
- public String getArtist() {
- return artist;
- }
- public int howMany(ArrayList<String> listeners) {
- int ans = 0;
- for (String listener : listeners) {
- listener = listener.toLowerCase();
- if (!uListeners.contains(listener)) {
- uListeners.add(listener);
- ans++;
- }
- }
- return ans;
- }
- }
- public class Main {
- public static void main(String[] args) {
- Song mountMoose = new Song("Mount Moose", "The Snazzy Moose");
- System.out.println(mountMoose.howMany(new ArrayList<String>(Arrays.asList("John", "Fred", "BOb", "carl", "RyAn"))));
- System.out.println(mountMoose.howMany(new ArrayList<String>(Arrays.asList("JoHn", "Luke", "AmAndA"))));
- }
- }
- //https://www.codewars.com/kata/6089c7992df556001253ba7d
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement