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
I need the full code for 6.1.3 code hs circles and squares please answer please help
Sloan [31]

In this exercise we have to use the knowledge in computational language in python  to write a code with circles and squares.

<h3>how to draw geometric figures in python?</h3>

<em>inputs = 100</em>

<em>radius</em>

<em>    draw_circle(radius);</em>

<em>    pendown()</em>

<em>    begin_fill()</em>

<em>    circle(radius)</em>

<em>    end_fill()</em>

<em>    penup()</em>

<em>left(90)</em>

<em>forward(radius*2)</em>

<em>right(90)  </em>

<em>penup()</em>

<em>setposition(0,-200)</em>

<em>color("gray")</em>

<em>bottom_radius = int(input("What should the radius of the bottom circle be?: "))</em>

<em>draw_circle(bottom_radius)</em>

<em>draw_circle(bottom_radius)</em>

See more about python at brainly.com/question/18502436

7 0
1 year ago
Express 0.0005 x 10-4 farads as picofarads
prohojiy [21]
0.0005 x 10⁻⁴ Farad = 0.000 000 05 Farad.
1 pF = 0.000 000 000 001 Farad

Divide them and get 50000 pF.
3 0
2 years ago
Read 2 more answers
Can you redact this image
spin [16.1K]

Answer:what???

Explanation:so

What

6 0
2 years ago
Power point how to insert diamond symbol
IceJOKER [234]
You got to "insert" and then you go to "shapes" and then you find the symbol you like and you drag and drop it onto the page. Then you can resize to the size and angle you would like it at.
4 0
3 years ago
Which service uses a broadband connection?
Sidana [21]

Answer:

d

Explanation:

because all in one question form

5 0
3 years ago
Other questions:
  • What CLI command can be issued in CentOS 7 to help you to see every "hop" that a connection makes, including all of the switches
    13·1 answer
  • You've been hired as a consultant to help an online store owner. You need to complete the implementation of conversion tracking
    5·1 answer
  • The __________ method can determine whether a string contains a value that can be converted to a specific data type before it is
    12·1 answer
  • economists measure the personal satisfaction someone gets from consuming goods and services with the concept of.....?
    6·1 answer
  • Identify the following​
    9·1 answer
  • State any three points of importance of local level profession​
    11·1 answer
  • The advancement of technology in our daily lives has changed how we interact with the world.
    10·1 answer
  • Which option on the Format tab is used to modify particular portions of the chart?
    13·1 answer
  • People’s personal information is collected _____. Select 4 options.
    7·2 answers
  • If I bought mine craft p.e. for 7.99 and hook my Micro soft account up, will i get java edition
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!