Question

Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If...

Java Project Name: IC19_WinningTheLottery

n this assignment, we're going to attempt to win the lottery! (**If you do actually win the lottery, please be sure to give back to your alma mater, Orange Coast College. We will be happy to put your name on the building!**)

Ok, time to get real. The Fantasy 5 (TM) lottery is a game in which 5 numbers from 1 to 36 are randomly drawn by the State of California. If you correctly guess all 5 numbers,  you win the jackpot of $75,000. If you guess 4 out of 5, you win $500. Finally, if you guess 3 out of 5, you win $15. No cash prizes are awarded for less than 3 correct guesses.

First, create an array named winningNumbers with space for 5 integer numbers.
Next, create an array named guessNumbers, also with space for 5 integer numbers.

Randomly generate 5 numbers from 1 to 36 and store each in a different location in the winningNumbers array. It would be useful to put this code in a static method (e.g. randomlyAssignNumbers), so that it may be reused later.
Display the winning lottery numbers to the console, so the user may see what they are.

Now, write a loop that will attempt to guess the winningNumbers by randomly assigning each element in the guessNumbers array a number between 1 to 36. Reuse the randomlyAssignNumbers method to simplify this task.

Create another static method (named howManyCorrect) that takes in two arrays as parameters (inputs). For example, the method definition might look like: public static int howManyCorrect(int[] guessNumbers, int[] winningNumbers). If the lengths of the two arrays are different, the method should return -1. Otherwise, the method should count how many of the elements in the guessNumbers array are the same elements in the winningNumbers array and return that value.

If the number correct is 5, your program should output "After 21233 guesses you won Fantasy 5! 5 out of 5 lottery numbers were correct. You win $75,000"
Otherwise, keep a counter of guesses (non-winning numbers) and continue to loop (randomlyAssignNumbers to the guessNumbersArray)

For example, here is a sample transaction with the user:

The winning lottery numbers are:

21 13 15 30 1 36

After spending $212337663.00, you won Fantasy5! 5 out of 5 lottery numbers were correct. You win $75,000

____________________________________________________________

I'm almost done i just need someone to help me with the rest.

________________________________________________________________

import java.text.NumberFormat;

public class WinningTheLottery {

public static void main(String[] args)

   {

       NumberFormat currency = NumberFormat.getCurrencyInstance();

       int[] winningNumbers = new int[5];

       int[] guessNumbers = new int[5];

       randomAssignNumbers(winningNumbers);

      

       do

       {

           randomAssignNumbers(guessNumbers);

       }

      

       while(howManyCorrect(winningNumbers, guessNumbers) < 5);

      

       System.out.println("The winning Lottery Numbers are: \n");

      

       System.out.println("After spending, " + "you won Fantasy5! 5 out of 5 lottery numbers were correct. You win " );      

          

  

   }

  

  

   public static void randomAssignNumbers(int[] anyArray)

   {

       for(int i = 0; i < anyArray.length; i++)

           anyArray[i] = (int)(Math.random() * 36 + 1);

   }

  

   public static int howManyCorrect(int[] array1, int[] array2)

   {

       int count = 0;

       for(int i = 0; i < array1.length; i++)

       {

           if(array1[i] == array2[i])

               count++;

       }

       return count;

  

   }

}

  

  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.text.NumberFormat;

public class WinningTheLottery {
  
   public static void main(String[] args) {
      
       NumberFormat currency = NumberFormat.getCurrencyInstance();
       int[] winningNumbers = new int[5];
       int[] guessNumbers = new int[5];
       int noOfGuesses = 0;
       int correctGuesses = 0;
      
       // Generate the winning lottery numbers
       randomAssignNumbers(winningNumbers);
       // Display the winning lottery numbers
       System.out.println("The winning Lottery Numbers are: ");
       for (int i : winningNumbers) {
           System.out.print(i + " ");
       }
       System.out.println();

       do {
           randomAssignNumbers(guessNumbers);
           correctGuesses = howManyCorrect(winningNumbers, guessNumbers);
           noOfGuesses += 5 - correctGuesses;   // counter of guesses (non-winning numbers)
       } while (correctGuesses < 5);
       System.out.println("After " + noOfGuesses + " guesses " + "you won Fantasy5! 5 out of 5 lottery numbers were correct. You win $75,000");
       // System.out.println("After spending, " + "you won Fantasy5! 5 out of 5 lottery numbers were correct. You win $75,000");
   }

   /**
   * Generates random numbers and assign the numbers to an array
   * @param anyArray
   */
   public static void randomAssignNumbers(int[] anyArray) {
       for (int i = 0; i < anyArray.length; i++)
           anyArray[i] = (int) (Math.random() * 36 + 1);
   }

   /**
   * Checks how many numbers are correct in both the arrays
   * @param array1
   * @param array2
   * @return
   */
   public static int howManyCorrect(int[] array1, int[] array2) {
       if (array1.length != array2.length)
           return -1;
      
       int count = 0;
       for (int i = 0; i < array1.length; i++) {
           if (array1[i] == array2[i])
               count++;
       }
       return count;
   }
}

SAMPLE OUTPUT:

The winning Lottery Numbers are: 18 9 16 8 11 After 193062926 guesses you won Fantasy5! 5 out of 5 lottery numbers were corre

The output shows the number of guesses. please mention how to calculate the total amount spent.

Add a comment
Know the answer?
Add Answer to:
Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If...
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
  • Need help with assignment This assignment involves simulating a lottery drawing. In this type of lottery...

    Need help with assignment This assignment involves simulating a lottery drawing. In this type of lottery game, the player picks a set of numbers. A random drawing of numbers is then made, and the player wins if his/her chosen numbers match the drawn numbers (disregarding the order of the numbers). More specifically, a player picks k distinct numbers between 1 and n (inclusive), as well as one bonus number between 1 and m (inclusive). "Distinct" means that none of the...

  • Can someone help me make the output of this code more spaced out? #include<iostream> #include<cstdlib> using...

    Can someone help me make the output of this code more spaced out? #include<iostream> #include<cstdlib> using namespace std; int main() {    int amount=1000,guess,answer,bet,count=0,win=0;    float per;    char ch;    cout<<"Welcome to the high-low betting game.\nYou have $1000 to begin the game.\nValid guesses are numbers between 1 and 100.\n";    do    {        cout<<"Please enter a bet:\n";        cin>>bet;        answer=rand()%100;        for (int i=0;i<6;i++)        {            cout<<"Guess "<<i+1<<":";   ...

  • Programming in java In this part of this Lab exercise, you will need to create a...

    Programming in java In this part of this Lab exercise, you will need to create a new class named ArrayShiftMult. This class carries out simple manipulation of an array. Then you should add a main method to this class to check that your code does what it is supposed to do. 1. Create a BlueJ project named LAB06 as follows: a. Open the P drive and create a folder named Blue), if it does not exist already. Under this folder,...

  • /**    * Returns the sum of "black hits" and "white hits" between the hiddenCode and...

    /**    * Returns the sum of "black hits" and "white hits" between the hiddenCode and    * guess. A "black hit" indicates a matching symbol in the same position in the    * hiddenCode and guess. A "white hit" indicates a matching symbol but different    * position in the hiddenCode and guess that is not already accounted for with    * other hits.    *    * Algorithm to determine the total number of hits:    *   ...

  • I need help on creating a while loop for my Java assignment. I am tasked to...

    I need help on creating a while loop for my Java assignment. I am tasked to create a guessing game with numbers 1-10. I am stuck on creating a code where in I have to ask the user if they want to play again. This is the code I have: package journal3c; import java.util.Scanner; import java.util.Random; public class Journal3C { public static void main(String[] args) { Scanner in = new Scanner(System.in); Random rnd = new Random(); System.out.println("Guess a number between...

  • java/javafx assignment: Island Paradise just started running their city lotto. You've been tasked with writing a...

    java/javafx assignment: Island Paradise just started running their city lotto. You've been tasked with writing a program for them. The program is going to allow to user to first select their lotto numbers. The program will then randomly generate the winning lotto numbers for the week and then check the winning numbers against the random ticket the user played in the Lotto to see how many numbers the user guessed correctly. The rules for lotto work as follows: Select 7...

  • Please help with this, and leave comments explainging the code you wrote, thank you for your...

    Please help with this, and leave comments explainging the code you wrote, thank you for your help Write a Lottery class that simulates a 6-number lottery (e.g. "Lotto"). The class should have an array of six integers named lotteryNumbers, and another array of six integers named userLotteryPicks. The class' constructor should use the Random class to generate a unique random number in the range of 1 to 60 for each of the 6 elements in the lotteryNumbers array. Thus, there...

  • This is a basic Java Question referencing Chapter 5 methods. The goal is to make a...

    This is a basic Java Question referencing Chapter 5 methods. The goal is to make a quick program that has the computer guess a number, after which the user will input if they would like to play the easy, medium or hard level. After this point the user will be allowed to guess a certain amount of times, before the computer tells them they are correct, incorrect, and gives them the guessed number. The Question is as follows: Define a...

  • Last name is Vhora 3. Write a java class named FinalyourLastName, which contains three methods: main,...

    Last name is Vhora 3. Write a java class named FinalyourLastName, which contains three methods: main, arrayMystery, and countTotalOdd. You need to create main method. Inside the main method...you need to create an integer array named myld that consists of each of the digits in your student ID, call arrayMystery method and print out myld, then call count TotaOdd method and print out the total number of odd digits in your ID. (8 points) The arrayMystery method is given as...

  • Design a program that allows you to experiment with different sort algorithms in Java. This program should allow you to...

    Design a program that allows you to experiment with different sort algorithms in Java. This program should allow you to easily plug-in new sort algorithms and compare them. Assume that input data is generated randomly and stored in a text file (have no less than 2000 items to sort). Do not restrict your program to only one data type, or to one ordering relationship. The data type, ordering relationship, and the sorting method must be input parameters for your program....

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