1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mario62 [17]
3 years ago
8

Write a test client for Randomthat checks that two methods, namely, nextGaussian()and nextLong()in the library operate as expect

ed. Take a command-line argument N, generate Nrandom numbers using each of the methods in Random, and print out their mean, and standard deviation.
Part 2: Implement a class that extends Random with a static method maxwellBoltzmann() that returns a random value drawn from a Maxwell-Boltzmann distribution with parameter s. To produce such a value, return the square root of the sum of the squares of three Gaussian random variables with mean 0 and standard deviation s. The speeds of molecules in an ideal gas have a Maxwell-Boltzmann distribution. Write a test client to test this new method, taking as command-line arguments N and sand prints N random numbers from the Maxwell Boltzmann distribution with parameter s.
Computers and Technology
1 answer:
xenn [34]3 years ago
5 0

Answer:

/ TestRandom.java

import java.util.Random;

public class TestRandom {

   // method to find the mean value of set of numbers

   // using Number as data type, so that it can represent both Double and Long

   // types needed for this program

   static double calculateMean(Number array[]) {

        double sum = 0;

        // summing values

        for (int i = 0; i < array.length; i++) {

            sum += array[i].doubleValue();

        }

        // finding average and returning it

        double avg = (double) sum / array.length;

        return avg;

   }

   // method to find the standard deviation value of set of numbers

   // using Number as data type, so that it can represent both Double and Long

   // types needed for this program

   static double calculateSD(Number array[], double mean) {

        // initializing sum of squared difference between each number and mean

        // to 0

        double sumSquaredDiff = 0;

        // looping

        for (int i = 0; i < array.length; i++) {

            // finding difference between current number and mean, squaring the

            // result, adding to sumSquaredDiff

            sumSquaredDiff += Math.pow(array[i].doubleValue() - mean, 2);

        }

        // finding variance

        double variance = (double) sumSquaredDiff / array.length;

        // finding square root of variance as standard deviation

        double sd = Math.sqrt(variance);

        return sd;

   }

   public static void main(String[] args) {

        // if no command line arguments given, displaying usage and quit

        if (args.length == 0) {

            System.out.println("Usage: java TestRandom <n>");

            System.exit(0);

        }

        // parsing first argument as integer N

        int N = Integer.parseInt(args[0]);

        // declaring a Double array and a Long array of size N

        Double gaussian[] = new Double[N];

        Long lng[] = new Long[N];

        // Random number generator

        Random random = new Random();

        // looping for N times

        for (int i = 0; i < N; i++) {

            // generating a guassian number, adding to array

            gaussian[i] = random.nextGaussian();

            // generating a long number, adding to array

            lng[i] = random.nextLong();

        }

        // finding average and standard deviation of both array values, we can

        // use the same functions for both types

        double avgGaussian = calculateMean(gaussian);

        double sdGaussian = calculateSD(gaussian, avgGaussian);

        double avgLong = calculateMean(lng);

        double sdLong = calculateSD(lng, avgLong);

        // displaying mean and standard deviation of both, formatted to 2 digits

        // after decimal point. the gaussian values will yeild a mean value

        // close to 0 and a standard deviation close to 1

        System.out.printf("Mean of %d gaussian values: %.2f\n", N, avgGaussian);

        System.out.printf("Standard deviation: %.2f\n", sdGaussian);

        System.out.printf("Mean of %d long values: %.2f\n", N, avgLong);

        System.out.printf("Standard deviation: %.2f\n", sdLong);

   }

}

Explanation:

You might be interested in
In Joan Woodward's study of the relationship between technology and structure, the structure that was the most technically compl
Arturiano [62]

Answer:

<em>Continuous Process Production</em>

Explanation:

In a study on the relationship between  industrial structure and performance, conducted by <em>Joan Woodward</em> from 1950 to 1959,  

she classified technology into <em>three groups</em>:  

  1. <em>Small batch and Unit technology  </em>
  2. <em>Large batch and Mass production </em>
  3. <em>Continuous process production </em>

She came to a  conclusion that the <em>continuous process production was the most complex</em> and  unit technology as the least.

4 0
3 years ago
What could prevent ping or traceroute responses from reaching the originating device beside network connectivity issues?
zysi [14]
Many admins set their firewalls to drop echo-request packets to prevent their networks from being mapped via "Ping Sweeps".

A remote possibility is that there's too many hops between the source and target and the packet's TTL expires.
3 0
3 years ago
Which of the following would be the most appropriate way to define a method that calculates and returns the final price, after t
Oksanka [162]

D. I hope it helped
5 0
2 years ago
Write a C program that stores the number 123.45 in the variable alpha, 98.76 in the variable beta, and 76.67 in the variable gam
Anon25 [30]

Answer:

C

Explanation:

the answer

8 0
2 years ago
what statement about constructors is false? group of answer choices all constructors are passed a pointer argument constructors
Hunter-Best [27]

A return type cannot exist in the constructor. It ought to produce and deliver fresh objects. Consequently, a compilation error would result.

Including a return type in a constructor declaration is not allowed. A constructor has to accept one or more input parameters. In the absence of explicitly declared constructors for the class, Java will give a default constructor. The name of the constructor should match the class name. 2) The compiler will automatically produce a default parameterless constructor for a class if you don't define one. 3) All instance variables are initialized to default values, such as 0, null, and super(), by the default constructor.

Learn more about variable here-

brainly.com/question/13375207

#SPJ4

4 0
10 months ago
Other questions:
  • The buttons on a specific tab are organized into logical Ribbons. <br> T<br> F
    12·2 answers
  • Mary uploaded some images on her website. She chose an image and downloaded it. She found that the image she saw on screen did n
    13·1 answer
  • Jim is a forensic specialist. He seized a suspect computer from a crime scene, removed the hard drive and bagged it, documented
    10·1 answer
  • Who is the last person appointed to the u.s supreme court
    11·1 answer
  • Pls Help Me!!!!!!!!!!! It won’t work when I connect to ITunes!
    12·1 answer
  • 1. Itemise the order in which BASIC executes arithmetic operation.
    13·1 answer
  • Should you ever force a CPU into<br>its socket?​
    15·1 answer
  • Read the citation example, and then use the drop-down menus to identify each part.
    8·2 answers
  • Jacob has a text file open, and he is typing on the keyboard. What is the best description of how the
    8·1 answer
  • failed logins or instances of denial of access to restricted files may be indicators of compromise. suggest where records of suc
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!