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 *...
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...
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: " +...
// Write a program that determines how many of each type of vowel are in an entered string of 50 characters or less. // The program should prompt the user for a string. // The program should then sequence through the string character by character (till it gets to the NULL character) and count how many of each type of vowel are in the string. // Vowels: a, e, i, o, u. // Output the entered string, how many of...
LE 7.1 Create a separate class called Family. This class will have NO main(). Insert a default constructor in the Family class. This is a method that is empty and its header looks like this: public NameOfClass() Except, for the main(), take all the other methods in LE 6.2 and put them in the Family class. Transfer the class variables from LE 6.2 to Family. Strip the word static from the class variables and the method headers in the Family...
Need help debugging. first class seems fine. second class is shooting an error on s = super.getString(prompt); third class is giving me an error in the while loop where int num = console.getInt("Enter an integer:"); //-------------------------------------------------------------------------- import java.util.Scanner; public class Console { private Scanner sc; boolean isValid; int i; double d; public Console() { sc = new Scanner(System.in); } public String getString(String prompt) { System.out.print(prompt); return sc.nextLine();...