Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Steps: Create a Java project in Eclipse, called Lab 2. Next create a java class

ID: 3783176 • Letter: S

Question

Steps:

Create a Java project in Eclipse, called Lab 2. Next create a java class called Dashboard. It should extend javafx.application.Application. This will be the main GUI for your lab, and it should use a VBox as the root node.

The first element in the VBox should be a button with the text label “Go!”.

The second element should be a text field where a user can enter the mean. By default, it should be 0.

The third element should be a text field where a user can enter the standard deviation. By default, it should be 10.

The fourth element should be a text field where a user can enter the number of data elements to randomly generate. Store these numbers that are generated in an ArrayList for later viewing.

In order to generate some data, you will need to use a NormalDistribution object for generating numbers:

NormalDistribution nDist = new NormalDistribution ( µ , );

use:           import org.apache.commons.math3.distribution.NormalDistribution;

With the distribution object, call the sample() function to generate a random number.

When the user clicks the “Go” button, your program should compute the following:

Maximum

Minimum

Mean (Average)

Weighted Average of the first 10 numbers: 10*list[0] + 9*list[1] … / 55

Median

Standard Deviation (SD)

Figure 1 Prototype of GUI

After calculating the data, open a second Stage window with a layout for displaying the results from step 6. Also, the window should use a ListView for displaying the raw data from the ObservableList that the user can scroll through.

When you are finished, demonstrate your work to the lab professor. Click the “Go” button several times to generate several results sets to show that in small data sets, the Mean, Median and SD can vary. Then generate a large data set (N = 106) to show that larger sample sizes tend to converge to the true values:

With N = 100:

With N = 106:

To create a second stage, use:

Stage newStage = new Stage();

            TextField tf = new TextField();

tf.setText(String.format("Mean: %f Max: %f Min:%f SD:%f Median:%f WeightedAverage:%f", mean, max, min, sd, median, weightedAverage));

            Scene newScene = new Scene(tf, 500,100);

            newStage.setScene(newScene);

.show();

The calculation of standard deviation is:

sd = Math.sqrt( differenceOfSquares( list, mean) / list.size() );// list are your numbers.

Write the differenceOfSquares( List<Double> list , double mean) as a function that iterates through every item and calculates the difference between it and the mean, squared:

double sum = 0;

list.forEach( item -> sum += (item – mean)*(item – mean) );

return sum;

To calculate the median, sort the list and get the middle element:

double median = list.get( list.size() / 2);// This is inefficient but works for now

Correctly calculating mean, max, min, median, weighted average, standard deviation:                                                                                                       +6

GUI design:                                                                                                     +2

           

Explanation / Answer

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;

public class SwingControlDemo {

   

   private JFrame mainFrame;

   private JLabel headerLabel;

   private JLabel statusLabel;

   private JPanel controlPanel;

   public SwingControlDemo(){

      prepareGUI();

   }

   public static void main(String[] args){

      SwingControlDemo swingControlDemo = new SwingControlDemo();     

      swingControlDemo.showSliderDemo();

   }

   private void prepareGUI(){

      mainFrame = new JFrame("Java Swing Examples");

      mainFrame.setSize(400,400);

      mainFrame.setLayout(new GridLayout(3, 1));

      mainFrame.addWindowListener(new WindowAdapter() {

         public void windowClosing(WindowEvent windowEvent){

            System.exit(0);

         }       

      });   

      headerLabel = new JLabel("", JLabel.CENTER);       

      statusLabel = new JLabel("",JLabel.CENTER);   

      statusLabel.setSize(350,100);

      controlPanel = new JPanel();

      controlPanel.setLayout(new FlowLayout());

      mainFrame.add(headerLabel);

      mainFrame.add(controlPanel);

      mainFrame.add(statusLabel);

      mainFrame.setVisible(true);

   }

   private void showSliderDemo(){

      headerLabel.setText("Control in action: JSlider");

      JSlider slider= new JSlider(JSlider.HORIZONTAL,0,100,10);

      slider.addChangeListener(new ChangeListener() {

         public void stateChanged(ChangeEvent e) {

            statusLabel.setText("Value : "

            + ((JSlider)e.getSource()).getValue());

         }

      });

      controlPanel.add(slider);     

      mainFrame.setVisible(true);    

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote