Question: This exercise builds on PP6.2. Write a class StringSet. A StringSet object is given a series of String objects. It stores these Strings (or a

This exercise builds on PP6.2. Write a class StringSet. A StringSet object is given a series of String objects. It stores these Strings (or a reference to them, to be precise) and can perform limited calculations on the entire series. A StringSet class has the following specification: // a single instance variable of type ArrayList // a single default constructor // mutator that adds a String newStr to the StringSet object void add(String newStr) // accessor that returns the number of String objects that have // been added to this StringSet object int size() // accessor that returns the total number of characters in all // of the Strings that have been added to this StringSet object int numChars() // accessor that returns the number of Strings in the StringSet // object that have exactly len characters int countStrings(int len) Modify your program for PP6.2 to create a StringSet object and add each String input by the user to the StringSet. Print the number of String objects in the StringSet, the total number of characters in all Strings in the StringSet, and the number of Strings that are 5 and 7 characters long. **PP6.2:

/****************************************************** * StringCharacters class prompts the user to enter * * a string, and then display it a character per line * ******************************************************/ //Header file section import java.util.Scanner;

public class StringCharacters {

//start main method public static void main(String[] args) { //variable declaration String str; // create an object for scanner class Scanner input = new Scanner(System.in);

//prompt the user to enter a string System.out.print("Enter a string: "); str = input.next();

//display the string one character per line System.out.println("The string one character per line: "); for(int pos = 0; pos < str.length(); pos++) System.out.println(str.charAt(pos));

} //end of main method } //end of characters class

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!