Question

In: Computer Science

*****Using Java Write a program that finds the standard deviation while also using a graphical user...

*****Using Java

Write a program that finds the standard deviation while also using a graphical user interface.

Solutions

Expert Solution

package test.gui.stddev;

import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class StdDevGUI {

public StdDevGUI(){
   Frame f= new Frame();   
  
f.setBackground(Color.orange);
f.setTitle("Standard Deviation Calculator");
  
TextField tf1,tf2;
Label l1,l2;
Button btn;
  
l1= new Label("Enter numbers(Comma separarated):");
l1.setBounds(50,60,300,20);
  
   tf1 = new TextField();
   tf1.setBounds(50,90,150,40);
  
  
   l2= new Label("Calculated Standard Deviation:");
   l2.setBounds(50,150,300,20);
  
tf2 = new TextField();
tf2.setBounds(50,180,150,40);
tf2.setEditable(false);
  
btn = new Button("Calculate SD");
btn.setBounds(50,240,100,30);
  
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
    String data = tf1.getText();
    String[] dataArr = data.split(",");
    double[] dblArr = new double[dataArr.length];
    for(int i = 0 ; i < dataArr.length; i++){
        dblArr[i] = Double.parseDouble(dataArr[i]);
    }
    double stdDev = calculateStdDev(dblArr);
    tf2.setText(String.valueOf(stdDev));
}
});
  
f.add(l1);
       f.add(tf1);
       f.add(l2);
       f.add(tf2);
       f.add(btn);
      
       f.setSize(400,400);
       f.setLayout(null);
       f.setVisible(true);
}
  
   public static void main(String []args) {       
   new StdDevGUI();
}

/**
* calculate standard deviation
* @param dataArr
* @return
*/
private static double calculateStdDev(double[] dataArr){
   double sum = 0.0;
   double stdDev = 0.0;
     
int length = dataArr.length;

for(double dbl : dataArr) {
sum = sum + dbl;
}
//System.out.println(sum);
double mean = sum/length;
for(double dbl: dataArr) {
   double powered = Math.pow(dbl - mean, 2);
   stdDev = stdDev + powered;
}
//System.out.println(stdDev);
return Math.sqrt(stdDev/length);
}
}

=======================

OUTPUT

=======================


Related Solutions

Using a while loop. Write a JAVA program that asks a user for an integer between...
Using a while loop. Write a JAVA program that asks a user for an integer between 1 and 9. Using the user input, print out the Fibonaccci series that contains that number of terms. Sample output: How many terms would like printed out for the Fibonacci Sequence? 7 Fibonacci Series of 7 numbers: 0 1 1 2 3 5 8
Using R: write a program that finds the standard deviation between each column. Find the average...
Using R: write a program that finds the standard deviation between each column. Find the average standard deviation for Set A and B, and then use that average to guess the next (fifth) column. Set A: 2, 5, 7, 8 Set B: 2, 3, 6, 9
​​​​​​​For java program. Write a while loop that will let the user enter a series of...
​​​​​​​For java program. Write a while loop that will let the user enter a series of integer values and compute the total values and number of values entered. An odd number will stop the loop. Display the number of iterations and the total of the values after the loop terminates. for Loop Write a for loop to display all numbers from 13 - 93 inclusive, ending in 3. Write a for loop to display a string entered by the user...
Write a C++ program that finds the minimum number entered by the user .The user is...
Write a C++ program that finds the minimum number entered by the user .The user is allowed to enter negative numbers 0, or positive numbers. The program should be controlled with a loop statement. Break statements is not allowed to break from loop. After each number inputted by the user, The program will prompt user if they need to enter another number. User should enter either Y for yes or N for no. Make Sure the user enters either Y...
(Using Matlab) and "while" function 1.   Write a program that prompts the User for if they...
(Using Matlab) and "while" function 1.   Write a program that prompts the User for if they would like to enter a real number. If yes, prompt the User for the real number. Continue to do this until the User enters “no” to the first question. After the User enters “no”, display the average of all the numbers entered. (Using Matlab) and "while" function 2.   Write a program that prompts the User for if they would like to enter a real...
Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
Using Java, write a program named MyAngles that will prompt the user for the measure of...
Using Java, write a program named MyAngles that will prompt the user for the measure of the three sides of a triangle and then reports the measurement of each interior angle of the triangle and the area of the triangle.
JAVA Program Write a program that prompts the user for data until the user wishes to...
JAVA Program Write a program that prompts the user for data until the user wishes to stop (you must have a while loop) (You must read in at least 8 to 10 sets of voter data using dialog boxes) The data to read in is: The registration of the voter (Democrat, Republican or other) The gender of the voter The Presidential candidate the voter is choosing (Trump or Biden) Which candidate has done better to manage the economy? (Trump or...
Write a program that calculates mean and standard deviation for four user entered values. The most...
Write a program that calculates mean and standard deviation for four user entered values. The most common measures of a sample are the mean and the standard deviation. the mean is the sum of the values divided by the number of elements in the data set. The dispersion - or spread in the values - is measured by the standard deviation The equation for the mean is x¯ = x1 + x2 + · · · + xn The equation...
***Using Java Using the switch/case construct, write a program that takes a character from the user...
***Using Java Using the switch/case construct, write a program that takes a character from the user and classifies it as a number (‘1’,’2’, ‘3’, …), a letter from the alphabet (‘A’, ‘a’, ‘B’, ‘b’, …, ‘Z’, ‘z’), an arithmetic operator (‘+’, ‘-‘, ‘/’, ‘*’, ‘%’), a comparison operator (‘<’, ‘>’, ‘=’), punctuation (‘!’, ‘?’, ‘,’, ‘,’, ‘:’, ‘;’), and all other characters as a Special Character, and informs the user of the same. If the user entered the character A,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT