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
PROCEDURE: Therapeutic infusion of saline solution with 5% dextrose IV, 500 ml for dehydration, lasting 48 minutes. what is the
Valentin [98]

Answer:

no

Explanation:

yes<em><u> </u></em><em><u>b</u></em><em><u>e</u></em><em><u>c</u></em><em><u>o</u></em><em><u>u</u></em><em><u>c</u></em><em><u>e</u></em><em><u> </u></em><em><u>n</u></em><em><u>o</u></em><em><u>t</u></em><em><u> </u></em><em><u>a</u></em><em><u>r</u></em><em><u>a</u></em><em><u>n</u></em><em><u>c</u></em><em><u>e</u></em><em><u> </u></em><em><u>t</u></em><em><u>h</u></em><em><u>e</u></em><em><u> </u></em><em><u>n</u></em><em><u>a</u></em><em><u>m</u></em><em><u>e</u></em><em><u> </u></em><em><u>o</u></em><em><u>f</u></em><em><u> </u></em><em><u>f</u></em><em><u>e</u></em><em><u>g</u></em><em><u>e</u></em><em><u>u</u></em><em><u>r</u></em><em><u> </u></em><em><u>s</u></em><em><u>p</u></em><em><u>e</u></em><em><u>c</u></em><em><u>h</u></em>

6 0
3 years ago
An articulated robot has a T-type wrist axis that can be rotated a total of 2 rotations (each rotation is a full 3600 ). It is d
Svetllana [295]
T pose my guy cuz my friend here Justin is next to me
8 0
3 years ago
Which of these is a Microsoft certification for system engineers
kow [346]

Answer: B. MCSE

Explanation:

Microsoft offers various courses and certifications for different careers in the IT industry. One such career is system engineering where the MCSE which stands for Microsoft Certified Solutions Expert is offered.

This certification proves that one is proficient with technologies such as server infrastructure, data platforms and business intelligence. Prospective careers apart from sound engineering include Network management and Database Analysis.

7 0
3 years ago
In a(n) ____, the programmer uses a programming language (in context free grammar) to tell the computer what to accomplish and h
Mamont248 [21]

A 5GL fifth-generation languages a programming language design to solve given problem without programmer. The user only needs to solve the problem and condition without implementing an algorithm.

Explanation:

First Generation Language

The first generation language is called low- level style because they were used at a superficial level of abstraction. First-generation language referred to as the native language.

Second Generation Language

The second-generation language is also low-level language or assembly language. The second level of language uses the concept of mnemonics for the writing program. Symbolic name are used.

Third Generation Language

The third-generation language overcomes the first and second-generation languages. Third generation language is considered as high- level language because the target is to focus on the logic of the program.

Fourth Generation Language

The language of generation required a lot of time and effort that affect programmers.The fourth-generation was developed to reduce the time, cost, and effort.

Fifth Generation Language

The programming language of this generation focuses on constraints programming. The fifth-generation programming languages are Artificial Intelligence and Artificial Neural Network.

6 0
3 years ago
In an If-Then-Else statement, the Else clause marks the beginning of the statements to be executed when the Boolean expression i
kari74 [83]

Answer:

False

Explanation:

The definition for the If-Then-Else structure is as follows:

IF (<em>boolean_condition</em>)  

THEN (<em>commands_for_true</em>)  

ELSE (<em>commands_for_false</em>)

When there is an ELSE sentence, its commands are to be executed whenever previous conditions where not evaluated as true .

7 0
3 years ago
Other questions:
  • The bit width of the LRU counter for a 32 KB 16-way set associative cache with 32 Byte line size is
    13·1 answer
  • public class BaseballTeam { private String city, mascot; private int numberOfPlayers; @Override public boolean equals(Object obj
    10·1 answer
  • Notice in the topology there are 3 network ranges that would be translated based on the ACL created. What will happen if more th
    6·1 answer
  • An automated search feature used by search engines to find results that match your search terms is called a spider or ?
    5·1 answer
  • Secops focuses on integrating the need for the development team to provide iterative and rapid improvement to system functionali
    14·1 answer
  • 9. DIMMs used in servers can provide additional reliability if they use what specific technology.
    8·1 answer
  • Create a Python dictionary that returns a list of values for each key. The key can be whatever type you want.
    9·1 answer
  • What is the purpose of criteria and constraints? How do they shape design?
    10·1 answer
  • Please help me on this it’s due now
    5·1 answer
  • Does every loop structure require curly braces?<br> A. yes<br> B. no
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!