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
If you tap or click the increase font size button too many times and make the font size too big, you can tap or click the _____
ioda
You can click the ctrl and minus  button at the same time
7 0
3 years ago
How does voting help in a social news site?
Inessa05 [86]
It helps spread the word about certain candidates in an upcoming election.
6 0
3 years ago
What are computer virus ? Explain in detail.In your answer include symptoms and prevention (3each)
Elenna [48]

Answer:

Explanation:

A computer virus is a form of malicious software that piggybacks onto legitimate application code in order to spread and reproduce itself.

Like other types of malware, a virus is deployed by attackers to damage or take control of a computer. Its name comes from the method by which it infects its targets. A biological virus like HIV or the flu cannot reproduce on its own; it needs to hijack a cell to do that work for it, wreaking havoc on the infected organism in the process. Similarly, a computer virus isn't itself a standalone program. It's a code snippet that inserts itself into some other application. When that application runs, it executes the virus code, with results that range from the irritating to the disastrous.

Computer virus symptoms

How can you tell if a virus has slipped past your defenses? With some exceptions, like ransomware, viruses are not keen to alert you that they've compromised your computer. Just as a biological virus wants to keep its host alive so it can continue to use it as a vehicle to reproduce and spread, so too does a computer virus attempt to do its damage in the background while your computer still limps along. But there are ways to tell that you've been infected. Norton has a good list; symptoms include:

Unusually slow performance

Frequent crashes

Unknown or unfamiliar programs that start up when you turn on your computer

Mass emails being sent from your email account

Changes to your homepage or passwords

7 0
2 years ago
You are setting up a small network. The customer has decided to change his internet service provider (ISP) to EtherSpeed. The IS
salantis [7]

Home pc1 becouse it is the right one

3 0
2 years ago
For safety, the lights on your vehicle must be in good working condition. Which statement about
bija089 [108]
I think the answer is a but I am not for sure
7 0
3 years ago
Read 2 more answers
Other questions:
  • In Java :
    11·1 answer
  • What are the planes used to allow SDN to virtualize parts of the physical network so that it can be more quickly and easily reco
    6·1 answer
  • When transporting data from real-time applications, such as streaming audio and video, which field in the ipv4 header can be use
    14·1 answer
  • Using python:
    10·1 answer
  • Limitations of the information systems used by tesco​
    7·1 answer
  • The area surrounding your car that can't be seen from the driver's seat is called
    14·2 answers
  • What factor(s) should be considered when determining whether a business is too far based on the query and the user location? Sel
    10·1 answer
  • Find the basic period and basic frequency of the function g(t)=8cos(10πt)+sin(15πt)
    9·1 answer
  • Vegetable farming is a good source of income explain this statement<br>​
    5·1 answer
  • Derek has to create a technical design of a complex floor plan using CAD. What will be most helpful for Derek to use to create t
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!