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
5 of 10
DaniilM [7]

Answer:

what

Explanation:

3 0
2 years ago
¿ cuales son las características de revolución industrial?
Daniel [21]

Answer:

La producción industrial a gran escala, especialmente de alimentos. ... El desarrollo de nuevas industrias como la textil, la siderúrgica (metales) o la minera. La sustitución del hierro por el acero, un material más duro y resistente.

Espero que esto sirva!

7 0
3 years ago
Lynn has created a quarterly sales report using a word processor. The document is confidential, and Lynn wants to secure it with
sweet-ann [11.9K]
Stop cheating



It’s b
3 0
2 years ago
Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have alre
Fudgin [204]

Answer:

The c++ program to implement the while loop is given below.

#include <iostream>

using namespace std;

int main() {

  // declaration of integer variables

   int k, n, total;

   // initialization of integer variables

   k=1, n=4, total=0;

//  loop executed till value of k becomes equal to value of n

   while( k <= n ){

       // cube of every integer is added to the variable total

       total = total + ( k * k * k );

       // value of k is incremented to go to the next number

k = k + 1 ;

   }  

   return 0;

}  

Explanation:

The program begins with the declaration of integer variables.  

int k, n, total;

This is followed by initialization of these variables.

k=1, n=4, total=0;

The while loop runs over the variable k which is initialized to 1. The loop runs till value of k reaches the value of integer n.

First, cube of k is computed and added to the variable total.

After first execution of the loop, total is initialized to the cube of 1.

Next, value of variable k is incremented by 1 so that k is initialized to next integer.

After first execution of the loop, k is incremented from 1 to 2.

while( k <= n )

{

total = total + ( k * k * k );

k = k + 1 ;

   }

When the value of k reaches the value of integer n, the cube of n is calculated and added to the variable, total.

When k is incremented, it becomes more than n and hence, loop gets terminated.

As the return type of main is int, the program terminates with the statement shown below.

return 0;

No output is displayed as it is not mentioned in the question.

No user input is taken as it is mentioned that integer variables are already initialized.

4 0
3 years ago
A persons decision to take action without being asked is
Nimfa-mama [501]

Answer:

Initiative

Explanation:

Initiative: the power or opportunity to act or take charge before others do.

5 0
3 years ago
Other questions:
  • A network engineer is configuring a network to be able to relay IPv6 packets. The network only supports IPv4 and does not have d
    11·1 answer
  • Tasks:_______.
    7·1 answer
  • For the Address Block 195.200.0.0/16 a. If you have 320 Customers that need 128 addresses/customer - will there be enough addres
    14·1 answer
  • Consider the following short paragraph: On a computer with a single core CPU, attempting to program real concurrency between two
    6·1 answer
  • JPG is considered a lossy file format. What does this mean?
    15·2 answers
  • Which task is not possible with VLOOKUP?
    10·2 answers
  • What might a designer need to consider when choosing an appropriate energy source for products and power systems
    15·1 answer
  • How many questions do you have to answer before you can use direct messages on Brainly?
    13·2 answers
  • A type of user interface that features on- screen objects, such a menus and icons, manipulated by a mouse.
    7·1 answer
  • What does a companys code of ehtics cover
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!