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
  • CAN YOU PLEASE DO THIS IN JAVA! WILL LEAVE GOOD RATING THANK YOU Modify your program...

    CAN YOU PLEASE DO THIS IN JAVA! WILL LEAVE GOOD RATING THANK YOU Modify your program that reads grades from the user, so that it has a method that checks if a particular input is valid i.e. as long as the user types invalid input, the user should be given another chance to enter input (it would also be good to let the user know that their input is invalid). Moreover, only a valid grade should be used in computing...

  • Credit card numbers follow certain patterns. A credit card number must have between 13 and 16...

    Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits. It must start with: 4 for Visa cards 5 for Master cards 37 for American Express cards 6 for Discover cards IBM proposed an algorithm for validating credit card numbers. The algorithm is used to determine if a card number is entered correctly or if a credit card is scanned correctly by a scanner. Almost all credit card numbers are generated following this...

  • 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,...

  • IN JAVA Overview In this project you will implement a Java program that will print several...

    IN JAVA Overview 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 the user to decide between different forms...

  • 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)

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