StringSetjava Can you please help me the JAVA program Write
StringSet.java
Can you please help me the JAVA program?
Write a WidgetView application. create a class StringAnalysis.
This class has an event handler inner class extending WidgetViewActionEvent
StringSet sSet
JTextField inputStr
JLabel numStr
JLabel numChar
create a WidgetView object
create sSet
create a local variable JLabel prompt initialized to \"Enter a String\"
create inputStr with some number of columns
create a local variable JButton pushMe initialized to \"Push to include String\"
create numStr initialized to \"Number of Strings: 0\"
create numChar initalized to \"Number of Characters: 0\"
create an event handler object and add it as a listener to pushMe
add prompt, inputStr, pushMe, numStr and numChar to your WidgetView object.
------------------------------------------------------
Here is OLD requirement. https://www.chegg.com/homework-help/questions-and-answers/stringsetjava-please-help-java-program--please-show-output-also-q15958409
------------------------------------------------------
Here is the code from OLD requirement:
class StringSet
{
//An instance variable of type String[]
String[] set;
//An int instance variable that indicates the number of String objects that the StringSet currently contains.
int numOfStrings;
//A no argument constructor.
public StringSet()
{
numOfStrings = 0;
set = new String[10];
}
//A mutator that adds a String newStr to the StringSet object.
void add(String newStr)
{
set[numOfStrings++] = newStr;
}
//An accessor that returns the number of String objects that have been added to this StringSet object.
int size()
{
return numOfStrings;
}
//An accessor that returns the total number of characters in all of the Strings that have been added to this StringSet object.
int numChars()
{
int sum = 0;
for(int i = 0; i < numOfStrings; i++)
sum += set[i].length();
return sum;
}
//An accessor that returns the number of Strings in the StringSet object that have exactly len characters.
int countStrings(int len)
{
int count = 0;
for(int i = 0; i < numOfStrings; i++)
if(set[i].length() == len)
count++;
return count;
}
}
And the code for StringSetTester.java is:
import java.util.*;
class StringSetTester
{
public static void main(String[] args)
{
Scanner kybd = new Scanner(System.in);
System.out.print(\"How many strings will you enter? \");
int numStr = kybd.nextInt();
kybd.nextLine();
StringSet ss = new StringSet();
for(int i = 0; i < numStr; i++)
{
System.out.print(\"Enter string \" + (i+1) + \": \");
String temp = kybd.nextLine();
ss.add(temp);
}
System.out.println(\"The size of the StringSet is: \" + ss.size());
System.out.println(\"The number of characters in StringSet is: \" + ss.numChars());
System.out.println(\"The number of strings of length 5 are: \" + ss.countStrings(5));
System.out.println(\"The number of strings of length 7 are: \" + ss.countStrings(7));
}
}
============================================================================
Output shoud look like this:
0-InitialWindow
4-ThirdStringEntered
Enter a String Push to include string Number of Strings: 0 Number of Characters: 0Solution
class StringSet
{
//An instance variable of type String[]
String[] set;
//An int instance variable that indicates the number of String objects that the StringSet currently contains.
int numOfStrings;
//A no argument constructor.
public StringSet()
{
numOfStrings = 0;
set = new String[10];
}
//A mutator that adds a String newStr to the StringSet object.
void add(String newStr)
{
set[numOfStrings++] = newStr;
}
//An accessor that returns the number of String objects that have been added to this StringSet object.
int size()
{
return numOfStrings;
}
//An accessor that returns the total number of characters in all of the Strings that have been added to this StringSet object.
int numChars()
{
int sum = 0;
for(int i = 0; i < numOfStrings; i++)
sum += set[i].length();
return sum;
}
//An accessor that returns the number of Strings in the StringSet object that have exactly len characters.
int countStrings(int len)
{
int count = 0;
for(int i = 0; i < numOfStrings; i++)
if(set[i].length() == len)
count++;
return count;
}
}
And the code for StringSetTester.java is:
import java.util.*;
class StringSetTester
{
public static void main(String[] args)
{
Scanner kybd = new Scanner(System.in);
System.out.print(\"How many strings will you enter? \");
int numStr = kybd.nextInt();
kybd.nextLine();
StringSet ss = new StringSet();
for(int i = 0; i < numStr; i++)
{
System.out.print(\"Enter string \" + (i+1) + \": \");
String temp = kybd.nextLine();
ss.add(temp);
}
System.out.println(\"The size of the StringSet is: \" + ss.size());
System.out.println(\"The number of characters in StringSet is: \" + ss.numChars());
System.out.println(\"The number of strings of length 5 are: \" + ss.countStrings(5));
System.out.println(\"The number of strings of length 7 are: \" + ss.countStrings(7));
}
}


