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...
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.
(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...
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...
Write a Java program using using WHILE loop to find the sum of all integers between...
Write a Java program using using WHILE loop to find the sum of all integers between 200 to 250 which are divisible by 7. Sample Output: Numbers between 200 and 250, divisible by 7: 203 210 217 224 231 238 245 The sum is: 1568
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT