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
HURRY PLEASE ITS A TEST
laiz [17]

<em>A.)</em>

<em>It's either A or D both of them stand out and make sense to me so I think that it'll be right if you choose A or D.</em>

<em>-Ɽ3₮Ɽ0 Ⱬ3Ɽ0</em>

8 0
3 years ago
Given three variables, a, b, c, of type double that have already been declared and initialized, write a statement that prints ea
mihalych1998 [28]

Answer:

The statement is written in Java.

  1. System.out.printf("%.5f %.5f %.5f",a,b,c);

Explanation:

Presume that there are three variable a, b and c which have already been declared and initialized with 4.014268319, 14309, 0.00937608 respectively.

To print each of the value with 5 digits to the right of the decimal point, we can use printf() method. We create a format specifier %.5f which is a placeholder of a floating point value. The .5 will specify five digits to the right of the decimal point.

We just create three similar format specifiers ( one for variable a, b, and c, respectively) and include them into printf() method. This will print the output as follows:

4.01427 14309.00000 0.00938  

6 0
3 years ago
Compare the two types of formatting that IDE devices must go through. What is the primary difference between the two?
Andrei [34K]
A quick format<span> changes the file system while the </span>full format<span> also checks the </span>drive for bad sectors.  <span>The scan for bad sectors is the reason why the Full </span>format<span> takes twice as long as the </span>Quick format<span>. If you choose the </span>Quick format<span> option, the </span>format<span> removes address files from the partition, but does not scan the disk for bad sectors.</span>
7 0
3 years ago
Read 2 more answers
A company's ____________ is the percentage of the total target market for the product that belongs to the company.
grigory [225]

a companys Market share is the percentage of the total target market for the product that belongs to the company

3 0
3 years ago
Isla is writing a report on the best roller coasters in America. Which device could help her with this?
Ulleksa [173]

Answer: a device that can help could be a map.. she could learn about that place then see if its coasters are better.

Explanation: i dunno if i'm right

~shina~

4 0
2 years ago
Other questions:
  • Problems with using a single Local Area Network (LAN) to interconnect devices on a premise include ______.
    12·1 answer
  • Alonzo collects bugs. He has created a fascinating display of large insects. Collecting bugs is a(n) _____ to Alonzo.
    10·2 answers
  • A switch is a central network device that connects network nodes such as workstations and servers in a physical ____ topology
    14·1 answer
  • An important task that the operating system performs is ____, which keeps track of the files stored on a computer so that they c
    15·1 answer
  • Question # 4
    8·2 answers
  • Which of the following is part of Connections Academy's AUP regarding the use of the school'supplied technology
    7·2 answers
  • A web application is an example of:
    7·1 answer
  • 1. When the Cisco 2950 switch is first turned on, it behaves like a hub. Why is this so, and what must happen before the switch
    5·1 answer
  • What are storage devices ​
    5·2 answers
  • In English there are five vowel letters in the alphabet: A, E, I, O, U. For the purposes of this exercise we won't count Y as a
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!