Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the getUniques and getDupes methods in the UniquesDupes class. Uniques are values that occur in the original list at least once. Duplicates are values

Complete the getUniques and getDupes methods in the UniquesDupes class. Uniques are values that occur in the original list at least once. Duplicates are values that occur in the original list more than once.

Use the String split method to seperate the string. input.split(" ") returns a string array where the original input string has been seperated by spaces. For example, "a b cd e".split(" ") returns a string array containing {"a", "b", "cd", "e"}.

Sample Output

Original   : a b c d e f a c e a e

Uniques    : [a, b, c, d, e, f]

Duplicates : [a, c, e]

 

 

Main.java

import java.util.*;

class Main {

   public static void main(String[] args) {

       String[] str = new String[3];
       str[0] = "a b c d e f a c e a e";
       str[1] = "one two three one two three six seven one two";
       str[2] = "1 2 3 4 5 1 3 4 5 1 3 4 5 6";

       for (int i = 0; i < str.length; i++) {
           System.out.println("Original   : " + str[i]);
           System.out.println("Uniques    : " + UniquesDupes.getUniques(str[i]));
           System.out.println("Duplicates : " + UniquesDupes.getDupes(str[i]));
           System.out.println();
       }

   }
}

 

UniquesDupes.java

import java.util.*;

public class UniquesDupes {

   /**
    * Returns a Set containing the unique values in the given input string. Uniques
    * are values that occur in the original list at least once.
    */

   public static Set getUniques(String input) {

       return null;
   }

   /**
    * Returns a Set containing the unique duplicate values in the given input
    * string. Duplicates are values that occur in the original list more than once.
    * Note: The add method for the Set class returns false if the value already
    * exists in a Set.
    */
   public static Set getDupes(String input) {

       return null;
   }
}

 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

import javautil public class UniquesDupes Returns a Set containing the uniq... blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Question

Answered: 1 week ago