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 Java program called Decision that includes a while loop to prompt the user to...
Write a Java program called Decision that includes a while loop to prompt the user to enter 5 marks using the JOptionPane statement and a System. Out statement to output a message inside the loop highlighting a pass mark >= 50 and <= 100. Any other mark will output a messaging stating it’s a fail.
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.
Using Java Prime numbers. Write a program that prompts the user for an integer and then...
Using Java Prime numbers. Write a program that prompts the user for an integer and then prints out all prime numbers up to that integer. For example, when the user enters 20, the program should print 2 3 5 7 11 13 17 19 Recall that a number is a prime number if it is not divisible by any number except 1 and itself. Use a class PrimeGenerator with methods nextPrime and isPrime. Supply a class PrimePrinter whose main method...
USING THE SWITCH STATEMENT - Write a java program that asks the user to enter the...
USING THE SWITCH STATEMENT - Write a java program that asks the user to enter the number of their favorite month of the year – obviously, that would be 1 – 12. Write a switch statement that takes the number and converts it to the fully spelled out name [ex. 3 would be MARCH] . Be sure to build in error message to catch any invalid data entries such as 0 or 13 etc. Print out the number that was...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT