Question: Write a class StringSet. A StringSet object is given a series of up to 10 String objects. It stores these Strings (or a reference to

Write a class StringSet. A StringSet object is given a series of up to 10 String objects. It stores these Strings (or a reference to them, to be precise) and can perform limited calculations on the entire series. The StringSet class has the following specification:

// an instance variable of type String[]

// an int instance variable that indicates the number of String objects that the StringSet currently contains

// a single no-argument constructor // a mutator that adds a String newStr to the StringSet object. If adding the new String to the String[] succeeds, the add method returns true.

// If adding the new String to the String[] fails (maybe the array is already full, for example), add returns false. boolean add(String newStr) // an accessor that returns the number of String objects that have been added to this StringSet object int size()

// an accessor that returns the total number of characters in all of the Strings that have been added to this StringSet object int numChars()

// an accessor that returns the number of Strings in the StringSet object that have exactly len characters int countStrings(int len)

Write a class StringSetTester that has a main method. It should ask the user for the number of Strings to add to a StringSet object. Afterward, use StringSet's size and numChars methods to print information about the collection of Strings entered. Also print the number of Strings that are exactly 5 and 7 characters long.

Hint: because Scanner's nextInt and nextLine process whitespace differently, you may want to use code similar to the following Scanner kybd = new Scanner(System.in); System.out.print("How many strings will you enter? "); int numStr = kybd.nextInt(); // stops after the number, leaves end of line or other whitespace kybd.nextLine(); // "eats" everything up to and including the next newline // the next kybd.nextLine() will read user input.

This is what I have so far:

public class StringSet { private StringSet [] array; private int numOfStrings; StringSet(){ StringSet array = new StringSet(); numOfStrings = 0; } public boolean add(String x) { int i = 0; if (i > 10) { for(i = 0; i > array.length; i++) { array[i] = String x; } } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!