StringSet.java Can you please help me the JAVA program? Write a WidgetView appli
ID: 3775034 • Letter: S
Question
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: 0Explanation / Answer
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; public class Server extends Thread { public ServerSocket s; public Socket p1, p2; public PrintWriter bis1, bis2; public BufferedReader bos1, bos2; public Server() { try { s = new ServerSocket(5_000, 1714); } catch (IOException e) { e.printStackTrace(); } } public void run() { try { p1 = s.accept(); p2 = s.accept(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { bis1 = new PrintWriter(p1.getOutputStream()); bis2 = new PrintWriter(p2.getOutputStream()); bos1 = new BufferedReader(new InputStreamReader(p1.getInputStream())); bos2 = new BufferedReader(new InputStreamReader(p2.getInputStream())); } catch (IOException e) { e.printStackTrace(); } while (p1.isClosed() || p2.isClosed()) { // if one of the players disconnect, the match will end. try { String p1 = bos1.readLine(); // what p1 says String p2 = bos2.readLine(); // what p2 says if (!p1.equalsIgnoreCase("")) { // if what p1 says is something if(p1.startsWith("my position x=")) { p1 = p1.substring(15); float x = Float.parseFloat(p1); bis2.write("his position x=" + x); } else if(p1.startsWith("my position y=")) { p1 = p1.substring(15); float y = Float.parseFloat(p1); bis2.write("his position y=" + y); } } if (!p2.equalsIgnoreCase("")) { // if what p1 says is something if(p2.startsWith("my position x=")) { p2 = p2.substring(15); float x = Float.parseFloat(p2); bis1.write("his position x=" + x); } else if(p2.startsWith("my position y=")) { p2 = p2.substring(15); float y = Float.parseFloat(p2); bis1.write("his position y=" + y); } } } catch (IOException e) { e.printStackTrace(); } } } }