Answered step by step
Verified Expert Solution
Question
1 Approved Answer
StringSet Write a class StringSet. A StringSet object is given a series of up to 10 String objects. It stores these Strings (or a reference
StringSet
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 Sanity Check - To help avoid these issues you'll find attached file StringSetSanityCheck.java. Place this file in your StringSet project and compile your program. If there are any problems with your method signatures, you'll get a compile error in StringSetSanityCheck. Correct your code to in StringSet as necessary.
public class StringSetSanityCheck { //This code verifies that the signatures for StringSet class //methods are correct. This code does not validate //the code in those methods. public static void SanityCheck(){ StringSet objStrSet0 = new StringSet(); objStrSet0.add(""); int int0 = objStrSet0.size(); int0 = objStrSet0.numChars(); int0 = objStrSet0.countStrings(0); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started