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
satela [25.4K]
3 years ago
7

Question 2 In this question you are asked to calculate probabilties for the discrete uniform and exponential distribution. Make

changes to H3_Q2.java to accomplish the following tasks. a. Print a menu to the screen asking the user to either type the number 1 to choose "discrete uniform" or the number 2 to choose "exponential". The tool should print out an error message and exit if the user types in anything other than one of those two numbers. b. If the user selects discrete uniform, the program should request a lower bound a, an upper bound b and value of x from the user. Your code should check that all values are integers and that the upper bound is greater than the lower bound. The code should also check that a ≤ x ≤ b. c. If the user selects exponential then the program should request a value of λ and x. Your should check that both values are doubles and that x > 0. d. Using the distribution chosen by the user, calculate P(X = x) and P(X ≤ x) and display the results to the screen with appropriate labels.
Computers and Technology
1 answer:
sasho [114]3 years ago
7 0

Answer:

Hi there! The question is asking to make changes to the H3_Q2.java program however there is no such program attached. Nevertheless, the requirements in the question can be addressed in a new H3_Q2.java program that i've listed below.

Explanation:

We can use the Scanner util in Java for prompting user input. The method nextInt() and nextDouble() allow only values of types "int" and "double" respectively. I have used the "switch" statement to direct the program based on user selection of menu item. The checks are printed with the "System.out.println" command and the program exits in case of error or invalid input. Finally, the calculation of probability simply requires you to replace the comment with the formula for the probability calculation based on the method chosen.

H3_Q2.java

import java.util.Scanner;

public class H3_Q2 {

 public static void main(String args[]) {

   // print main menu for user selection

   System.out.println("Please type 1 to select 'discrete uniform' or 2 to select 'exponential'");

   Scanner scan = new Scanner(System.in);

   int selection = scan.nextInt();

   switch(selection) {

     case 1:

       // discrete uniform

       System.out.println("Please enter a lower bound value a: ");

       int a = scan.nextInt();

       System.out.println("Please enter a upper bound value b: ");

       int b = scan.nextInt();

       System.out.println("Please enter a value x: ");

       int x = scan.nextInt();

       if (b <= a) {

         System.out.println("The upper bound value b should be greater than the lower bound value a");

         System.exit(0);

       }

       if (a > x) {

         System.out.println("The value x should be greater than the lower bound value b");

         System.exit(0);

       }

       if (b < x) {

         System.out.println("The value x should be greater than the lower bound value b");

         System.exit(0);

       }

       break;

     case 2:

       // exponential

       System.out.println("Please enter a lambda value for exponential: ");

       double lambda = scan.nextDouble();

       System.out.println("Please enter a value x: ");

       double d_x = scan.nextDouble();

       if (d_x <= 0.0) {

         System.out.println("The value x should be greater than 0");

         break;

       } else {

         // calculate P(X = x) and P(X ≤ x)

         // result = calculateExponential()

         System.out.println("The calculation for the exponential method given the lambda value " + lambda + " and the value of x " + d_x + " is: ");

       }

       break;

     default:

       System.out.println("Invalid input. Exiting..");

       break;

   }

 }

}

You might be interested in
What tab appears that allows for charts to be formatted when a chart is selected?
djyliett [7]
in the Design section you can format your selected Chart
8 0
2 years ago
Typically, when an organization purchases Internet access from an Internet Service Provider (ISP), the ISP will grant it
hodyreva [135]

Answer:

(B) A single public IP address that it can use for NAT

Explanation:

Because the IPV4 IP protocol is still used today, the number of available IP addresses is limited (only 4,294,967,296 addresses in the world), for this reason, the most correct practice is the assignment of a single public IP to those companies that acquire services from an ISP, with some few exceptional cases of companies that own several.

So that the company's addressing can be executed successfully, the use of NATs is enabled, this allows the translation of network addresses, allowing the company to have as many private networks as necessary and that these can be communicated Correctly with the global network, the Internet, through the public IP of the company.

7 0
3 years ago
Felicia's Wi-Fi connection to her phone is extremely slow. However, her
Alex Ar [27]

Answer: fake water all across the road

Explanation:

3 0
2 years ago
Read 2 more answers
Which type of chart is best for highlighting trends in data?
STALIN [3.7K]
Pie chart I believe that is the right answer

8 0
3 years ago
Read 2 more answers
Which of the following is a geolocation service on an Internet browser?
seropon [69]
It may be D) because it is actually a simplified version of Google maps.
7 0
3 years ago
Read 2 more answers
Other questions:
  • What is “centrifugal bumble puppy”? why is it important for games to require a complicated apparatus?
    10·2 answers
  • Put the following numbers in order from greatest to least:
    13·1 answer
  • It will gain you more knowledge, intensify your soft skills, strong work ethics and grow your network. What is it?​
    12·2 answers
  • If you were setting up a network with 100 nodes and you wanted no more than 25 nodes per segment: what devices and connections w
    9·1 answer
  • Encapsulation is the process of “packaging” information prior to transmitting it from one location to another. true or false
    14·1 answer
  • In addition to using comments and track changes, you can also use the comparison feature for reviewing documents. In this activi
    11·1 answer
  • [This is on Edhesive (coding and programming)]
    8·2 answers
  • String[][] arr = {{"Hello,", "Hi,", "Hey,"}, {"it's", "it is", "it really is"}, {"nice", "great", "a pleasure"},
    11·1 answer
  • Easy<br> What is your favorite Anime<br> Mine is Attack On Titan at the moment
    7·2 answers
  • Caps lock key is used to type alphabets. _________​
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!