Question

Convert Project #1 into a GUI program, following the following requirements: Provide two text fields: one...

Convert Project #1 into a GUI program, following the following requirements:

  • Provide two text fields: one receives the length of the sequence, and the second receive the sequence (each number separated by a comma). There may, or may not, be space in between the comma and the number element.
  • Provide a clear button that has an event listener attached to it. When pressed, the two text fields are emptied. The event listener should be defined and implemented as an anonymous inner class.
  • Provide a radio button group. Within that group, provide 4 radio buttons: sum, avg, min, max. Attach an event listener to each radio button. When the specific radio button is pushed by the end user, the corresponding calculation is performed, and the result is displayed in a pop up GUI box. Define an inner class for this event listener.
  • Utilize a layout of your choice for the design. Recommended are FlowLayout or GridLayout.

Feel free to augment the program further, if you have time. Recommended are playing with mouse events and nesting components (panels).

Please upload your source code to this assessment. Please name your file as follows:

CS401Recitation10SC_YOURLASTNAME_YOURLOGINID.java [please put all source code in one file -- all class/interface/method definitions, and the actual application]

For reference, Project #1:  For this project, you are tasked with creating a program that performs basic numerical analysis on a sequence of integer numbers inputted into your program. Ask the end user for a number, which indicates the length of the sequence (how many numbers are in the data set to be inputted by the end user and analyzed by your program). Then, ask the end user to enter each integer number via the keyboard, one at a time, that comprises the sequence. Do not store each number in memory - perform the computations as the data is entered. Compute the average of the sequence, the summation of all numbers in the sequence, the minimum number in the sequence, and the maximum number in the sequence. Print your data statistics out to the end user via monitor output.

please help ASAP!!! - I just need a  general structure would help me get started!!!! - I don't need the entire code :)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

1. Design the Interface as per the question ( as below )

Enter Length of Sequence Enter the Sequence (Separated by comma eg: 1,5,6) O Sum Average Minimum Maximum Calculate Clear

2. Code for Calculate Button for calculating Sum ( Coded only to calculate Sum )

(Paste inside the click event of the button)

----------------------------START------------------------------------------------------------------------

private void btnCalculate_Click(Object sender, tangible.EventArgs e)
{
           int seqFromUser = CharCountWithoutComma(txtSequence.Text);
           if (Integer.parseInt(txtSequenceLength.Text.toString()) == seqFromUser)

           {
               if (rbSum.Checked == true)
               {
                   if (!txtSequence.Text.endsWith(","))
                   {
                       int sumOfSequence = Sum(txtSequence.Text.trim());
                       JOptionPane.showMessageDialog("The sum of the Sequence: " + String.valueOf(sumOfSequence), "Sum");
                   }
                   else
                   {
                       JOptionPane.showMessageDialog("Remove comma at the end of the sequence and proceed", "Incorrect Sequence");
                   }

               }
           }
           else
           {
               JOptionPane.showMessageDialog("The sequence length is not matching", "Error");
           }


}

public final int CharCountWithoutComma(String str)
{
           String[] arr = str.split("[,]", -1);
           String allChars = "";
           for (String s : arr)
           {
               allChars += s;
           }
           int length = allChars.length();
           return length;
}
public int Sum(string sumNumbers)
{
string[] arr = sumNumbers.Split(',');
int sum = 0;
foreach (string s in arr)
{
sum += Convert.ToInt32(s);
}

return sum;
}

----------------------------START------------------------------------------------------------------------

Code Explanation to find SUM

----------------------------

1. CharCountWithoutComma function will calculate the length of the sequence entered by the user

2. Checking whether the "length of the sequence == the actual sequence length"

3. Also, checking the sequence should not contain any comma at the end (eg: 1,4,6,) to avoid parsing error

(Point 2 & 3 are some additional checking from my side to enhance the program)

4. If all the conditions ok, the sum function will calculate the sum of the sequence.

Output

-----------

Catching Incorrect Sequence Length

Enter Length of Sequence Enter the Sequence 1.2.3.4.5.6.7 (Separated by comma eg: 1,5,6) Sum o Average O Minimum Maximum - Ca

Enter Length of Sequence 5 Enter the Sequence 1.2.3.4.5.6.7 (Separated by comma eg: 1,5,6) O O Average Minimum Maximum Calcul

Catching comma at the end of the sequence

Enter Length of Sequence 5 Enter the Sequence 1.2.3.4.0 (Separated by comma eg: 1 (Separated by comma eg: 1,5,6) O Sum Averag

Calculating Sum

Enter Length of Sequence 5 Enter the Sequence 1.2.3.4.5 (Separated by comma eg: 1,5,6) Sum o Average Minimum Maximum Calculat

Code to Clear text fields

----------------------------------

--------------------------------------------START--------------------------------------------------------------

private void btnClear_Click(Object sender, tangible.EventArgs e)
{
           txtSequenceLength.Text = "";
           txtSequence.Text = "";
}

​​​​​​​------------------------------------------------------------END--------------------------------------------------------------

Please Note:

1. I coded only for the SUM function.

2. Just modify the "Sum" to calculate the other like Average, Min, Max (Small change is required)

3. Use NetBeans

----------------------------------------------ALL THE BEST-------------------------------------------------------------------


Add a comment
Know the answer?
Add Answer to:
Convert Project #1 into a GUI program, following the following requirements: Provide two text fields: one...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Instructions: Add radio button options for filing status to the tax calculator program of Project 1....

    Instructions: Add radio button options for filing status to the tax calculator program of Project 1. The user selects one of these options to determine the tax rate. The Single option’s rate is 20%. The Married option is 15%. The Divorced option is 10%. The default option is Single. Be sure to use the field names provided in the comments in your starter code. Given Code: It also gives us the code for a module but that is like 3000...

  • JAVA Create a simple Graphical User Interface (GUI) in java with the following requirements:  The...

    JAVA Create a simple Graphical User Interface (GUI) in java with the following requirements:  The interface components will appear centered in the interface, and in two rows. o Row one will have a Label that reads “Please enter a valid integer:” and a Text Field to take in the integer from the user. o Row two will have a Button that when pressed converts the integer to binary  The conversion will be completed using recursion – A separate...

  • please write JAVA code: Your Own Exception Class Write a text-based (non-GUI) program to read in...

    please write JAVA code: Your Own Exception Class Write a text-based (non-GUI) program to read in file that contains only positive numbers and outputs to the screen the sum of all numbers. Create your own exception class that describes the situation of a non-positive number. In your program, use this exception to handle this situation. Use other exception classes from the Java standard library to handle other I/O situations.

  • Programming Exercise 8.3 | Instructions Write a GUI-based program that allows the user to convert temperature...

    Programming Exercise 8.3 | Instructions Write a GUI-based program that allows the user to convert temperature values between degrees Fahrenheit and degrees Celsius. The interface should have labeled entry fields for these two values. breezypythongui.py temperatureconvert... + 1 2 File: temperatureconverter.py 3 Project 8.3 4 Temperature conversion between Fahrenheit and Celsius. 5 Illustrates the use of numeric data fields. 6 • These components should be arranged in a grid where the labels occupy the first row and the corresponding fields...

  • CSC151 Stock Portfolio GUI Project Goal You are to write a GUI program that will allow...

    CSC151 Stock Portfolio GUI Project Goal You are to write a GUI program that will allow a user to buy, sell and view stocks in a stock portfolio. This document will describe the minimum expected functions for a grade of 90. Your mission is to “go and do better.” You’ll find a list of enhancement options at the end of this document. Objectives By the end of this project, the student will be able to • write a GUI program...

  • The JavaFX framework provides more than one way to handle events. For event handlers, we could...

    The JavaFX framework provides more than one way to handle events. For event handlers, we could use inner classes, anonymous inner classes, or the new Java 8 feature of lambda expressions. In this discussion, you will explore these different ways of writing event handles in JavaFX. To prepare for this discussion, you must unzip the attached NetBeans project zip file (U4D1_HandleEvents.zip) and load it into your NetBeans IDE. The project uses an inner class to handle the click event on...

  • Project overview: Create a java graphics program that displays an order menu and bill from a...

    Project overview: Create a java graphics program that displays an order menu and bill from a Sandwich shop, or any other establishment you prefer. In this program the design is left up to the programmer however good object oriented design is required. Below are two images that should be used to assist in development of your program. Items are selected on the Order Calculator and the Message window that displays the Subtotal, Tax and Total is displayed when the Calculate...

  • Please design a Java GUI application with two JTextField for user to enter the first name...

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

  • Add radio button options for filing status to the tax calculator program of Project 1. The...

    Add radio button options for filing status to the tax calculator program of Project 1. The user selects one of these options to determine the tax rate. The Single option’s rate is 20%. The Married option is 15%. The Divorced option is 10%. The default option is Single. For the calculations from Project 1, I was gonna use this. TAX_RATE = 0.20 STANDARD_DEDUCTION = 10000.0 DEPENDENT_DEDUCTION = 3000.0 # Request the inputs gross Income = float(input("Enter the gross income: "))...

  • AA. Final Project - Improved JavaFX GUI Personal Lending Library Description: In this project we will...

    AA. Final Project - Improved JavaFX GUI Personal Lending Library Description: In this project we will improve our personal lending library tool by (1) adding the ability to delete items from the library, (2) creating a graphical user interface that shows the contents of the library and allows the user to add, delete, check out, or check in an item. (3) using a file to store the library contents so that they persist between program executions, and (4) removing the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT