Help with StringAnalysis
Write a WidgetViewer application. Create a class StringAnalysis.
This class has an event handler inner that extends WidgetViewerActionEvent
it has instance variables
In the constructor,
Your event handler should add inputStr's contents to sSet and set inputStr to "". It should update numStr and numChar labels to contain sSet's current information.
Note: the same event handler that handles button pushes can, with no modification, handle the <enter> key for a JTextField. For the adventurous, use inputStr's addActionEvent method to add your event handler. (You can use the same object you added to pushMe--you don't even have to create a new one). Then run your program, enter text in the inputStr field, and press the enter key.
Grading Elements
****************************
StringSet.java -
*****************************
public class StringSet {
private String[] stringArray;
private int stringCount;
public StringSet() {
stringArray = new String[10];
stringCount = 0;
}
public boolean add(String newStr) {
if (stringCount < 10) {
stringArray[stringCount] = newStr;
stringCount++;
}else if (stringCount == 0) {
return false;
}
return true;
}
public int size() {
return stringCount;
}
public int numChars() {
int amount = 0;
for(int i = 0; i < stringArray.length; i++) {
amount = amount + stringArray[i].length();
}
return amount;
}
public int countString(int len) {
int amount = 0;
for(int i = 0; i < stringCount; i++) {
if(stringArray[i].length() == len) {
amount++;
}
}
return amount;
}
}
PROGRAM:
import javax.swing.*;
import java.awt.event.*;
public class StringAnalysis{
StringSet sSet;
JTextField inputStr;
JLabel numStr;
JLabel numChar;
StringAnalysis()
{
sSet=new StringSet();
JFrame f= new JFrame("String Analysis"); //replace this with WidgetViewer
JLabel en=new JLabel("Enter a String:");
en.setBounds(50, 10, 100, 100);
numStr=new JLabel("Number of Strings: 0");
numStr.setBounds(50, 200, 400, 100);
numChar=new JLabel("Number of Characters: 0");
numChar.setBounds(50, 250, 400, 100);
inputStr=new JTextField();
inputStr.setBounds(50, 100, 400, 50);
JButton pushMe=new JButton("Push to include String");
pushMe.setBounds(50, 150, 400, 50);
pushMe.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String s=inputStr.getText();
sSet.add(s);
String ns=numStr.getText();
ns=ns.substring(0, ns.length() - 1)+sSet.size();
numStr.setText(ns);
String nc=numChar.getText();
nc=nc.substring(0, nc.length() - 1)+sSet.numChars();
numChar.setText(nc);
inputStr.setText("");
}
});
f.add(en);f.add(inputStr);f.add(pushMe);
f.add(numStr);f.add(numChar);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String[] args) {
new StringAnalysis();
}
}
Help with StringAnalysis Write a WidgetViewer application. Create a class StringAnalysis. This class has an event...
/** * File: GradeCalculator . java * Description: Instances of this class are used to calculate * a course average and a letter grade. In order to calculate * the average and the letter grade, a GradeCalculator must store * two essential pieces of data: the number of grades and the sum * of the grades. Therefore these are declared as object properties * (instance variables). * Each time calcAverage (grade) is called, a new grade is added to *...
Need help debugging Create a GUI application that accepts student registration data. Specifications: The text box that displays the temporary password should be read-only. The temporary password consists of the user’s first name, an asterisk (*), and the user’s birth year. If the user enters data in the first three fields, display a temporary password in the appropriate text field and a welcome message in the label below the text fields. If the user does not enter data, clear the...
Following class is only part of my program that uses a hash table to simulate a market's client database, client class is my main class which asks user to input client names and then creates a hash table which then users can look up client names. wasn't able to upload everything as it is too much code, but what I need is to modify my client class instead of me inputting data line by line, the program should read from...
Please design a Java GUI application with two JTextField for user to enter the first name and last name. Add two JButtons with action events so when user click on one button to generate a full name message from the user input and put it in a third JTextField which is not editable; and click on the other button to clear all three JTextField boxes. Please run the attached nameFrame.class file (Note: because there is an actionhandler inner class in...
please help me debug this Create a GUI for an application that lets the user calculate the hypotenuse of a right triangle. Use the Pythagorean Theorem to calculate the length of the third side. The Pythagorean Theorem states that the square of the hypotenuse of a right-triangle is equal to the sum of the squares of the opposite sides: alidate the user input so that the user must enter a double value for side A and B of the triangle....
So I am having probelms with figuring out how to do this program the part in bold is the part I dont know how to do. This is in JAVA. What I have so far is shown below the question, this is right upto what I have to do next. Choose Your Operation Write a program that uses a WidgetViewer object to do the following: Generate two random integers between 1 and 9 (inclusive). Name one of them x, the...
Thank you in advance. Create a class called Main and write the main method. I need help with calling the printChart method Declare a variable to hold the grade as it is read in Declare 5 variables to hold counts to count the number of As, Bs, Cs, etc declare a variable to hold the class name and ask the user to enter the name of the class whose grades are going to be entered. Write a loop that reads...
I have to create two classes one class that accepts an object, stores the object in an array. I have another that has a constructor that creates an object. Here is my first class named "ShoppingList": import java.util.*; public class ShoppingList { private ShoppingItem [] list; private int amtItems = 0; public ShoppingList() { list=new ShoppingItem[8]; } public void add(ShoppingItem item) { if(amtItems<8) { list[amtItems] = ShoppingItem(item);...
Java class quiz need help~ This is the Backwards.java code. public class Backwards { /** * Program starts with this method. * * @param args A String to be printed backwards */ public static void main(String[] args) { if (args.length == 0) { System.out.println("ERROR: Enter a String on commandline."); } else { String word = args[0]; String backwards = iterativeBack(word); // A (return address) System.out.println("Iterative solution: " + backwards); backwards = recursiveBack(word); // B (return address) System.out.println("\n\nRecursive solution: " +...
Need help debugging. Create an application that keeps track of the items that a wizard can carry. console application which has no errors: import java.util.Scanner; public class Console { private static Scanner sc = new Scanner(System.in); public static String getString(String prompt) { System.out.print(prompt); String s = sc.nextLine(); return s; } public static int getInt(String prompt) { int i = 0; boolean isValid = false; while (!isValid) { System.out.print(prompt);...