1 answer

Exercise 2 Write a program that simulates the Texas Powerball lottery. You will have to do resear...

Question:

I HAVE A PROBLE WITH THIS JAVA PROBLEM CAN ANYONE HELP ME PLEASE.Exercise 2 Write a program that simulates the Texas Powerball lottery. You will have to do research to find out how many numb

Exercise 2 Write a program that simulates the Texas Powerball lottery. You will have to do research to find out how many numbers are drawn, and what the range(s) of the numbers are. For this exercise you need to create a class called "Powerbali", which exposes a public function called play'. This function accepts several parameters , which represent the individual numbers the player wants to play. The function on the object should generate the correct amount of random numbers within the correct range(s), and compare the passed numbers to the drawing. This function should return a String that either tells the user that they unfortunately didn't win (if none of the user's numbers match the drawn numbers), or it tells the user the amount of correct numbers that were guessed, and which numbers were guessed correctly, e.g. "Congratulations, you guessed 3 numbers correct l, 2, 3” The class Powerball should overload the function play with one extra boolean parameter, which if passed as true, performs the number drawing over and over, until there occurs a drawing in which all the player's numbers match the randomly generated numbers. This function should return a String that says how many times a drawing was necessary to match the user's numbers Hint: this loop can potentially run for a very long time, and if you're unlucky, never produce a winner. Do not count on this loop to end, so you will have to be extra careful when implementing it, because testing it is not going to be trivial.

Answers

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

//class powerball
public class Powerball {
   /*
   * first play method to compare the passed numbers to compare random generated
   * numbers
   */
   public static String play(int... numbers) {
       Random rand = new Random();
       List<Integer> guessedNumbers = new ArrayList<>();
       String str;
       int count = 0;
       for (int num : numbers) {
           if (num == 1) {
               int random_number = rand.nextInt(num + 1);
               if (num == random_number) {
                   count++;
                   guessedNumbers.add(num);
               }
           } else {
               int random_number = rand.nextInt(num);
               random_number += 1;
               if (num == random_number) {
                   count++;
                   guessedNumbers.add(num);
               }
           }

       }
       if (count > 0) {
           str = "\"Congratulations, you guessed " + count + " numbers correct : ";
           for (Integer i : guessedNumbers) {
               str += i + ",";
           }
           str = str.substring(0, str.length() - 1) + "\"";
       } else {
           str = "Sorry !, Unfortunately you didn't win";
       }
       return str;
   }

   /*
   * second play method to take another input boolean which if passed as true,
   * performs the number number drawing over and over again until there occurs a
   * drawing in which all the players numbers match the randomly generated numbers
   */ public static String play(boolean input, int... numbers) {
       Random rand = new Random();
       String str;
       int count = 0;
       if (input == true) {
           for (int num : numbers) {
               int random_number = rand.nextInt(num);
               random_number++;
               if (random_number == num) {
                   count++;
               } else {
                   count++;
                   while (random_number != num) {
                       random_number = rand.nextInt(num);
                       random_number++;
                       count++;
                   }

               }
           }
           str = count + " many times drawing is necessary to match user's numbers";
       } else {
           List<Integer> guessedNumbers = new ArrayList<>();
           for (int num : numbers) {
               if (num == 1) {
                   int random_number = rand.nextInt(num + 1);
                   if (num == random_number) {
                       count++;
                       guessedNumbers.add(num);
                   }
               } else {
                   int random_number = rand.nextInt(num);
                   random_number += 1;
                   if (num == random_number) {
                       count++;
                       guessedNumbers.add(num);
                   }
               }

           }
           if (count > 0) {
               str = "\"Congratulations, you guessed " + count + " numbers correct : ";
               for (Integer i : guessedNumbers) {
                   str += i + ",";
               }
               str = str.substring(0, str.length() - 1) + "\"";
           } else {
               str = "Sorry !, Unfortunately you didn't win";
           }

       }

       return str;

   }

   public static void main(String[] args) {

      
       String str = play(1,3,4,8);
       System.out.println(str);
         
       String output = play(true, 1,3,4,8);
       System.out.println(output);

   }

}

Output

Eile Edit ource Refactor Navigate Search Project Bun Window Help Quick Access! : E | | Console X terminated> Powerbell leve A

.

Similar Solved Questions

1 answer
10. In the conversion of phenylalanine into phenylpyruvic acid (shown below), what is the co-factor that is utilized to make the functional enzyme that carries out this oxidative deamination transfor...
10. In the conversion of phenylalanine into phenylpyruvic acid (shown below), what is the co-factor that is utilized to make the functional enzyme that carries out this oxidative deamination transformation? CO-H S-phenylalanine A. PLP (pyridoxal monophosphate) B. PMP (pyridoxamine monophosphate) C. ...
1 answer
PART A&B (16%) Problem 5: A point charge of 4.8 pC is placed at the origin...
PART A&B (16%) Problem 5: A point charge of 4.8 pC is placed at the origin (x,-0) of a coordinate system, and another charge of-2.8 pC is placed placed on the x-axis at x2 = 0.27 m 50% Part (a) Where on the x-axis can a third charge be placed in meters so that the net force on it is zero? Grade ...
1 answer
How to know when is favorable and unfavorable in a flex budget income statement? ( for...
how to know when is favorable and unfavorable in a flex budget income statement? ( for question VI) Using the base information in IV. show a flex budget income stam inventory) for next year in variable costing format based on unit Assume price will increase to 553 per unit. All other costs with ...
1 answer
As current and future managers, you must be continually aware of how motivated your employees are....
As current and future managers, you must be continually aware of how motivated your employees are. We know that company culture, effective leadership, and social dynamics in the workplace are crucial to keeping your employees motivated. This chapter adds another potential dynamic to motivating your ...
1 answer
Infection control. Professional Nursing 1. From Hebden, J. (2012). Rationale for accuracy and consistency in applying...
Infection control. Professional Nursing 1. From Hebden, J. (2012). Rationale for accuracy and consistency in applying standardized definitions for surveillance of health care-associated infections. American Journal of Infection Control 40(2012). Accessed from http://www.ajicjournal.org/pb/assets/raw...
1 answer
A service provider measures availability over a month by dividing it into 10-minute intervals and performing...
A service provider measures availability over a month by dividing it into 10-minute intervals and performing a synthetic transaction testevery interval.  If the synthetic transaction test fails, the system is considered "down" for the entire 10 minute interval.  Scheduled...
1 answer
Gino's Restaurant is a popular restaurant in Boston, Massachusetts. The owner of the restaurant has been...
Gino's Restaurant is a popular restaurant in Boston, Massachusetts. The owner of the restaurant has been trying to better understand costs at the restaurant and has hired a student intern to conduct an activity- based costing study. The intern, in consultation with the owner, identified the foll...
1 answer
Use at least 3 sig fig. I will rate This projectile is launched on a 3-4-5...
use at least 3 sig fig. I will rate This projectile is launched on a 3-4-5 slope with an initial velocity v. of 100 feet per second at strikes a wall that is a distance d = 200 feet from the launch point. Find the height h at which the projectile strikes the wall. Report your answer in ft. hmax...
1 answer
Why the traditional vew of factor price equalization (e.g., Chinas's workers get richer, US workers get...
why the traditional vew of factor price equalization (e.g., Chinas's workers get richer, US workers get poorer until average wages are equalized) is wrong...
1 answer
54. In what federal election cycles did more black voters first start to align themselves with the Democrats (which...
54. In what federal election cycles did more black voters first start to align themselves with the Democrats (which had been the party of the white South) rather than with Lincoln's Republican Party? a. By the 1936 election (FDR) b. By the 1940 election (FDR) c. By the 1944 election (FDR) d. All...
1 answer
Please explain it. The angle θ is the angle of depression from E to T. This...
Please explain it. The angle θ is the angle of depression from E to T. This is the angle Al-Biruni measured as 0°34. (This is where you can see the picture is not to scale, as it would be a tiny angle.) The purpose of Al-Biruni's measurements was to find the radius and the circumferenc...
1 answer
I need help writing my introduction to this lab, what is the purpose of this lab...
I need help writing my introduction to this lab, what is the purpose of this lab ? Extra Credit Reverberation Time Theory Reverberation is the combined effect of multiple sound reflections in a room that results in a gradual decay of the sound heard by the listener after the source of sound stops...
1 answer
40) Do you think it is important for an employer to provide innovative or unique benefits?...
40) Do you think it is important for an employer to provide innovative or unique benefits? Why or Why not? 5 points Your answer 41) What should happen when a manager and an employee can not agree 5 points on performance goals? Your answer 5 points 42) What are some creative, and low cost/ no cost wa...
1 answer
Please help me solve!! than you! Question 7 During 2013, Grouper Corporation spent $152,640 in research and developme...
Please help me solve!! than you! Question 7 During 2013, Grouper Corporation spent $152,640 in research and development costs. As a result, a new product called the New Age Piano was patented. The patent was obtained on October 1, 2013, and had a legal life of 20 years and a useful life of 10 yea...
1 answer
U us muUa Essuie Slalla Ilmal u tribution. Draw a separate, well-labeled Normal curve for each...
U us muUa Essuie Slalla Ilmal u tribution. Draw a separate, well-labeled Normal curve for each par a. Find an approximate z-score that gives a left area of 0.7000. b. Find an approximate z-score that gives a left area of 0.9500....
1 answer
Why are the effects of Acetylcholinesterase Inhibitors effectively the same as the effects of Ach and...
Why are the effects of Acetylcholinesterase Inhibitors effectively the same as the effects of Ach and direct cholinergic agents? Why do anticholineric/cholinergic receptor blocking drugs like atropine (muscarinic antagonist) exhibit effects that are opposite those of Ach, Direct Cholinegic Drugs, an...
1 answer
Which of the following is not an economic increment event? a. receive raw materials b. receive...
Which of the following is not an economic increment event? a. receive raw materials b. receive vendors invoice c. receive cash d. produce finished goods e. receive returned goods...
1 answer
The more frequent the compounding the.... lesser the future value greater the amount deposited greater the...
The more frequent the compounding the.... lesser the future value greater the amount deposited greater the present value greater the effective interest rate...