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
PLEASE-I'M STUCK!!!!!!!!!!!!!!!!!!!!!!
Blababa [14]

Answer: Input is the answer.

8 0
2 years ago
What is a Type 10 SD card?
Semmy [17]

Answer: Class 10 refers to the read write speed of a memory card

Explanation:

5 0
1 year ago
You have been asked to write a username validation program for a small website. The website has specific rules on what constitut
umka21 [38]

Answer:

#function to validate username

def valid_username(username):

   

   #checking is length is between 8 to 15

   length_valid=True

   if(len(username)<8 or len(username)>15):

       length_valid=False;

   

   #checking is string is alphanumeric

   alphanumeric=username.isalnum()

   

   #checking first_and_last Characters of string is not digit

   first_and_last=True

   if(username[0].isdigit() or username[len(username)-1].isdigit()):

       first_and_last=False

   

   #counting uppercase lowercase and numeric Characters in string

   uppercase=0

   lowercase=0

   numeric=0

   

   for i in username:

       if(i.isdigit()):

           numeric=numeric+1

       elif(i.isalpha()):

           if(i.isupper()):

               uppercase=uppercase+1

           else:

               lowercase=lowercase+1

               

   valid_no_char=True

   if(uppercase<1 or lowercase<1 or numeric<1):

       valid_no_char=False

           

 

   #printing the result

   print("Length of username: "+str(len(username)))

   print("All Characters are alpha-numeric: "+str(alphanumeric))

   print("First and last Character are not digit: "+str(first_and_last))

   print("no of uppercase characters in the username: "+str(uppercase))

   print("no of lowercase characters in the username: "+str(lowercase))

   print("no of digits in the username: "+str(numeric))

   

   #checking string is Valid or not

   if(length_valid and alphanumeric and first_and_last and valid_no_char):

       print("Username is Valid\n")

       return True

   else:

       print("username is invalid, please try again\n")

       return False

#loop runs until valid_username enterd by user

while(True):

   

   username=input("Enter a username: ")

   if(valid_username(username)):

       break

Explanation:

The code was created by considering all the required cases asked in the question.

In this program, I asked username from the user continuously until it enters a valid username

first it check for length of string

then check is string contains only alphanumeric characters

then first and last digit is or not

than no of uppercase lowercase and numeric character

using the above parameter declare username valid or not

3 0
3 years ago
Can you run microsoft office on a chromebook
zimovet [89]
Yes, you can Microsoft office in a Chromebook.
6 0
3 years ago
Why are user application configuration files saved in the user’s home directory and not under /etc with all the other system-wid
kodGreya [7K]

Explanation:

The main reason why is because regular users don't have permission to write to /etc. Assuming this is Linux, it is a multi-user operating system. Meaning if there are user-application configuration files within /etc, it would prevent users from being able to customize their applications.

6 0
3 years ago
Other questions:
  • List at least three things that are included as part of property rights.
    10·1 answer
  • To execute a prepared SQL statement, you can use the _______ and execute methods of the PDOStatement object to set parameter val
    9·1 answer
  • Casey Griggs is a very capable computer engineer. Recently, he noticed a problem that computer engineers have, and thought of a
    13·1 answer
  • How do the principles behind the Agile Manifesto suggest approaching architecture?A. Architecture emergesB. Architecture is not
    10·1 answer
  • Which of the following statements is true of a cookie? a. A cookie can create copies of itself and spread to other networks to e
    7·1 answer
  • Adjust list by normalizing When analyzing data sets, such as data for human heights or for human weights, a common step is to ad
    7·1 answer
  • Write an algorithm to show whether a given number is even or odd.
    14·1 answer
  • What caused accident? into passive voice​
    13·1 answer
  • When should you create an outline?
    7·1 answer
  • To determine what to study one Should first
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!