Question

Question 1 You have been asked to consider a random variable X that has 4 possible...

Question 1 You have been asked to consider a random variable X that has 4 possible outcomes. Those outcomes are X ={1,2,3,4}. Modify H3_Q1.java to accomplish the following tasks. a.

package studentWork;

import java.util.Scanner;

public class H3_Q1 {

    public static void main(String[] args)
    {
        Scanner scnr = new Scanner(System.in);

        //variables storing 4 outcomes entered by user
        double outcome1;
        double outcome2;
        double outcome3;
        double outcome4;

Addcodethatpromptstheuserfortheprobabilityassociatedwitheachofthe4outcomes(e.g. P(X = x)) and reads the values into the variables provided. b. Determine whether each individual probability given by the user in (a) is valid. For each invalid P(x), print “P(x) must be between 0 and 1” on a newline. c. Determine if the 4 values entered collectively satisfy the requirements of a probability distribution. If they do not, print “The sum of the individual outcome probabilities must sum to 1” on a newline.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
I have provided the code for it.Do give a thumps up.Any dobut in code please comment.

package studentWork;

import java.util.*;

public class H3_Q1

{

    public static void main(String args[])

    {

        Scanner scnr=new Scanner(System.in);

        double outcome1=scnr.nextDouble();

        double outcome2=scnr.nextDouble();

        double outcome3=scnr.nextDouble();

        double outcome4=scnr.nextDouble();

        System.out.println("probability associated with 1st outcome is "+outcome1);

        System.out.println("probability associated with 2nd outcome is "+outcome2);

        System.out.println("probability associated with 3rd outcome is "+outcome3);

        System.out.println("probability associated with 4th outcome is "+outcome4);

        if(0<=outcome1 && outcome1<=1){

            System.out.println("Valid");

        }

        else{

            System.out.println("P(1) must be between 0 and 1");

        }

        if(0<=outcome2 && outcome2<=1){

            System.out.println("Valid");

        }

        else{

            System.out.println("P(2) must be between 0 and 1");

        }

        if(0<=outcome3 && outcome3<=1){

            System.out.println("Valid");

        }

        else{

            System.out.println("P(3) must be between 0 and 1");

        }

        if(0<=outcome4 && outcome4<=1){

            System.out.println("Valid");

        }

        else{

            System.out.println("P(4) must be between 0 and 1");

        }

        if(outcome1+outcome2+outcome3+outcome4!=1f){

            System.out.println("The sum of the individual outcome probabilities must sum to 1");

        }

    }

}

Add a comment
Know the answer?
Add Answer to:
Question 1 You have been asked to consider a random variable X that has 4 possible...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You will need to think about problem solving. There are several multi-step activities. Design, compile and...

    You will need to think about problem solving. There are several multi-step activities. Design, compile and run a single Java program, StringEx.java, to accomplish all of the following tasks. Add one part at a time and test before trying the next one. The program can just include a main method, or it is neater to split things into separate methods (all static void, with names like showLength, sentenceType, lastFirst1, lastFirst), and have main call all the ones you have written...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

  • Step 4: Add code that discards any extra entries at the propmt that asks if you...

    Step 4: Add code that discards any extra entries at the propmt that asks if you want to enter another score. Notes from professor: For Step 4, add a loop that will validate the response for the prompt question:       "Enter another test score? (y/n): " This loop must only accept the single letters of ‘y’ or ‘n’ (upper case is okay). I suggest that you put this loop inside the loop that already determines if the program should collect...

  • Been working on this program for hours and keep getting error. PLEASE help and show a...

    Been working on this program for hours and keep getting error. PLEASE help and show a working output, Thank you Step 2: Declaring variables Examining the problem we need to have 2 variable to store integer input given by the user.     int x,y; Step 3: setting up Scanner object and scanning the inputs import java.util.Scanner; Create Scanner class object by using following syntax Scanner=new Scanner(System.in); /* give some name to the object which ever you want */ Ask the...

  • this is what i have so far but it does not work. please help thank you...

    this is what i have so far but it does not work. please help thank you Part 2: Perimeter of a Triangle Write a program named Triangle.java that asks for the lengths of the three sides of a triangle and computes the perimeter if the input is valid.The input is valid if the sum of every pair of two sides is greater than the remaining side. For example, the lengths 3, 4, and 5 define a valid triangle: 3 plus...

  • Consider the experiment of picking a four-digit PIN uniformly at random over all possible four-digit PINs,...

    Consider the experiment of picking a four-digit PIN uniformly at random over all possible four-digit PINs, and define the random variables: X = number of distinct digits (i.e. how many different digits appear once or more) Y = length of longest streak of the same digit Below are the values of the random variables for some sample outcomes: X(1,3,1, 3)) = 2, Y((1,3,1,3)) = 1, X(2, 4, 3, 3)) = 3, Y(2, 4, 3, 3)) = 2, X (2,2, 4,...

  • Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring...

    Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring a variable, you usually want to initialize it. Remember you cannot initialize a number with a string. Remember variable names are case sensitive. Use tabs or spaces to indent code within blocks (code surrounded by braces). Use white space to make your program more readable. Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs. Problem...

  • 10. A binomial distribution describes a random variable, X, that has 4 possible outcomes. Outcome 1...

    10. A binomial distribution describes a random variable, X, that has 4 possible outcomes. Outcome 1 has a probability of 25%, Outcome 2 has a probability of 15%, Outcome 3 has a probability of 20%. What is the probability of Outcome 4?    (5 pts)

  • Hello Guys. I need help with this its in java In this project you will implement...

    Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...

  • This question deals with extending already existing Java code via a while loop. Ask the user...

    This question deals with extending already existing Java code via a while loop. Ask the user how many year inputs he wants to check - an integer. Assume that the user always gives an input which is between 1 and 5 (inclusive). Next, ask the user for K number of year inputs where K = the number user has given as input before (inside a while loop). Check for each year input whether that year is a leap year or...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT