Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This exercise builds on PP6.2. Write a class StringSet. A StringSet object is gi

ID: 3672837 • Letter: T

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 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

Explanation / Answer

Please find the required code below :

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote