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;
}
}
}