Download our latest MNC Answers Application at Play Store. Download Now

Java Milestone Challenge Solution | TCS Fresco Play

Java Milestone Challenge Solution | TCS Fresco Play


Disclaimer: The primary purpose of providing this solution is to assist and support anyone who are unable to complete these courses due to a technical issue or a lack of expertise. This website's information or data are solely for the purpose of knowledge and education.

Make an effort to understand these solutions and apply them to your Hands-On difficulties. (It is not advisable that copy and paste these solutions).

All Question of the MCQs Present Below for Ease Use Ctrl + F with the question name to find the Question. All the Best!


Java Milestone Challenge Solution


import java.util.Arrays;

import java.util.List;

import java.util.Scanner;


import java.util.function.Function;

import java.util.function.Predicate;

/*

 * Create the Filter and Mapper classes here.

 */

 class Filter {

    public static Predicate<String> nameStartingWithPrefix(String prefix) {

        return n -> n.startsWith(prefix);

    }

}

class Mapper {

    public static Function<String, CharactersCount> getDistinctCharactersCount() {

        return s -> new CharactersCount(s, (int)s.chars().distinct().count());

    }

}


class CharactersCount {

    private final String name;

    private final Integer distinctCharacterCount;

    

    public CharactersCount(String name, Integer distinctCharacterCount) {

        this.name = name;

        this.distinctCharacterCount = distinctCharacterCount;

    }

    

    @Override

    public String toString() {

        return "\"" + this.name + "\" has " + this.distinctCharacterCount + " distinct characters.";

    }

}


public class Solution {

    private static final Scanner scanner = new Scanner(System.in);

    

    public static void main(String[] args) {

        List<String> names = Arrays.asList(

                "aaryanna",

                "aayanna",

                "airianna",

                "alassandra",

                "allanna",

                "allannah",

                "allessandra",

                "allianna",

                "allyanna",

                "anastaisa",

                "anastashia",

                "anastasia",

                "annabella",

                "annabelle",

                "annebelle"

        );

        

        names.stream()

                .filter(Filter.nameStartingWithPrefix(scanner.nextLine()))

                .map(Mapper.getDistinctCharactersCount())

                .forEachOrdered(System.out::println);

    }

}


**************************************************
Credit for the above notes, goes to the respective owners. 

If you have any queries, please feel free to ask on the comment section.
If you want MCQs and Hands-On solutions for any courses, Please feel free to ask on the comment section too.

Please share and support our page!