Ad
  • Default User Avatar

    Ok, but what about my error, have you got any suggestions?

  • Default User Avatar

    please don't use the issue tag to ask questions, its purpose is to keep track of maintenance tasks.

  • Default User Avatar

    Can someone help me? I have done a solution part, I've also made Tests and they work, but I cant complete the Kata. I've even checked solutions but there were no test cases. I'm already struggling with this error for two days but have no idea what have done wrong. The funny thing is that I have any statement with such name: mysteryColorAnalyzer, and also have instantiated only the class that implements an interface. So I'm lost, hope on your help. The error:
    src/test/java/MysteryColorAnalyzerTest.java:17: error: MysteryColorAnalyzerImpl is abstract; cannot be instantiated
    mysteryColorAnalyzer = new MysteryColorAnalyzerImpl();
    ^
    1 error

  • Default User Avatar

    Hi, I'm very new to Java interfaces and struggling with this one. So far I have eliminated all the error messages but one: "duplicate class: MysteryColorAnalyzer". I would appreciate it if someone could just give me a little nudge in the right direction. Here's my code:

    import java.util.List;
    import java.util.ArrayList;
    
    interface MysteryColorAnalyzer {
        /**
         * This method will determine how many distinct colors are in the given list
         *
         *
         * Colors are defined via the {@link Color} enum.
         *
         *
         * @param mysteryColors list of colors from which to determine the number of distinct colors
         * @return number of distinct colors
         */
      int numberOfDistinctColors(List mysteryColors);
        /**
         * This method will count how often a specific color is in the given list
         *
         *
         * Colors are defined via the {@link Color} enum.
         *
         *
         * @param mysteryColors list of colors from which to determine the count of a specific color
         * @param color color to count
         * @return number of occurrence of the color in the list
         */
      int colorOccurrence(List mysteryColors, Color color);
    }
    
    class MysteryColorAnalyzerImpl implements MysteryColorAnalyzer {
        public int numberOfDistinctColors(List mysteryColors) {
          ArrayList distinctColors = new ArrayList();
          for (int i = 0; i < mysteryColors.size(); i++) {
            Color thisColor = mysteryColors.get(i);
            if (distinctColors.indexOf(thisColor) == -1) {
              distinctColors.add(thisColor);
            }
          }
          return distinctColors.size();
        }
    
        public int colorOccurrence(List mysteryColors, Color color) {
          int occurrences = 0;
          for (int i = 0; i < mysteryColors.size(); i++) {
            Color thisColor = mysteryColors.get(i);
            if (thisColor.equals(color)) {
              occurrences++;
            }
          }
          return occurrences;
        }
    }
  • Custom User Avatar
    Note: ./src/main/java/MysteryColorAnalyzerImpl.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    
  • Custom User Avatar

    No sample tests.

  • Custom User Avatar

    Do you know what is a enum?

    If you don't know what is it, perhaps you should go look it up ;-)

  • Custom User Avatar

    Color is a enum, so...

  • Default User Avatar

    Some clarification would be needed about distinct colors. What makes a color a distinct? As far as I found on google it is quite subjective since it depends on a person's perception?

    So what features of a color have to be searched to find it distinct?

  • Custom User Avatar

    Approved

  • Custom User Avatar

    ;-)

  • Custom User Avatar
  • Custom User Avatar

    Yes.

    It's also effortless: you can just wrap the whole test with a for loop.

  • Custom User Avatar

    I added random tests as well.

    Is it good practice to run the random test multiple times with different random sets?

  • Custom User Avatar

    You're probably right. I'll add a random and non random tests just in case the random generator does a weird data collection which might let some incompleteness slip through.

  • Loading more items...