Question

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 numbers between 1 and 50
Twice every week 7 numbers are drawn at random
If a player matches all 7 numbers they win a million dollar prize
If a player matches 6 numbers they win $100,000
If a player matches 5 numbers they win $5,000
If a player matches 4 numbers they win $100.
If a player matches 3 numbers they win a free ticket.
Your program should work as follows. (NOTE:  I have listed some functions you need to include in your program – you may include other functions if you would like and they make your program more readable/efficient).
Step 1
Create an array named UserTicket to hold each of the user’s lotto number selections.
Create an array named WinningNums to hold the winning lotto numbers.
Step 2
Display the following menu:
ISLAND PARADISE LOTTO MODEL:
--------------------------------------------------
1) Play Lotto
q) Quit Program
Please make a selection:
If the selection is 1:
a. First ask the user their name and store it in an appropriate variable.
b. Next, call a function named getLottoPicks that asks the user to enter their 7 lotto number picks (selections) for the week. Each of the user’s lotto picks should be stored in the userTicket array. The lotto does NOT have duplicate numbers in it. Find a way to not allow duplicate numbers to be picked by the user. You may want to create another function called noDuplicates that checks to see if the user’s selection is already in the userTicket array. If the user enters a number already in the array, ask them to enter another number until they enter one that is not a duplicate.   This means the UserTicket array should contain no duplicate numbers.
c. Next, call a function named genWinNums that randomly generates the winning lotto numbers for the week based on the rules stated above and stores the winning lotto numbers in the winningNums array (so you are going to fill the winningNums array with random numbers between 1 and 50). Do not allow this function to generate duplicate winning numbers (if you design your noDuplicates function above well you should be able to re-use it to check for duplicates in the winningNums array).
HINT: There are two ways to avoid having duplicate numbers in an array. The first method is to check the array after each number is generated or entered to make sure that number is not already in the array. If the number generated/entered is already in the array a new number should be generated/entered. The second method involves sorting and checking that the numbers next to each other in the array after the sort are not the same.
d. The next step is to check the user’s lotto ticket (represented by the UserTicket array) to see if they have won any prizes in the Lotto game. Check each number the UserTicket array to see if that number is in the winningNums array and count how many numbers are matched.
Output
Display a report similar to the following showing user’s lotto results – the example output below assumes the user entered a name of “Alex” when the program started.
In the “Winnings” section of the report
Display: JACKPOT!!! - $1 MILLION if all 7 numbers were correct
Display: GREAT! - $100,000 if 6 numbers were correct
Display: LUCKY YOU! - $5,000 if 5 numbers were correct
Display: NOT BAD - $100 if 4 numbers were correct
Display: FREE TICKET if 3 numbers were correct
Display: SORRY NOTHING if 2 or less numbers were correct
Sample Output:-
ALEX'S LOTTO RESULTS
WINNING NUMBERS: 35 03 01 15 10 25 22
ALEX’S TICKET: 33 15 02 06 21 20 19
RESULTS:
You must show report.txt how you program runs exactly.
Number Matches: 1         
Winnings      : SORRY NOTHING
If the selection is q: Quit the program
If the selection is not q and not 1: Display an invalid selection message
Allow the user to play lotto as many times as they would like.

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

please rate - thanks

#include <iostream.h>
using namespace std;
bool NoDuplicates(int[],int,int);
void GenWinNums(int[],int);
void getLottoPicks(int[],int);
char menu(void);
int checkwins(int[],int[],int);
void results(int[],int[],int,int,string);
int main()
{int UserTicket[7],WinningNumbers[7],max=7;
int usercount=0,winningcount=0,i,matches=0;
char choice=1;
string name;
choice=menu();
while(choice!='q')
{cout<<"Enter your name:";
   getline(cin,name,'\n');
   getLottoPicks(UserTicket,max);
   GenWinNums(WinningNumbers,max);
   matches=checkwins(UserTicket,WinningNumbers,max);
   results(UserTicket,WinningNumbers,max,matches,name);  
   choice=menu();
}
return 0;
}
void results(int a[],int b[],int n,int m,string name)
{int i;
cout<<name<<"'s LOTTO RESULT\n******************\nWINNING TICKET NUMBERS: ";
for(i=0;i<n;i++)
   cout<<b[i]<<" ";
cout<<"\n"<<name<<"'s TICKET: \n";
for(i=0;i<n;i++)
   cout<<a[i]<<" ";
cout<<"\nRESULTS: \n******************\nNumber Matches "<<m<<"\nWinnings:";
switch(m)
{case 7:     cout<<"JACKPOT - $1 MILLION";break;
case 6:     cout<<"GREAT! - $100,1000";break;
case 5:     cout<<"LUCKY YOU! - $5,000";break;
case 4:     cout<<"NOT BAD - $100";break;
case 3:     cout<<"FREE TICKET";break;
default:    cout<<"SORRY NOTHING";break;
}
cout<<endl<<endl;
int enter=cin.get();          //get left over trash from buffer
return;
}
           

int checkwins(int a[],int b[],int n)
{int i,j,same=0;
   for(i=0;i<n;i++)
      for(j=i;j<n;j++)
          if(a[i]==b[j])
             {same++;
             cout<<i<<" "<<j<<" "<<a[i]<<" "<<a[j]<<" "<<same<<endl;
             }
return same;
}            
void GenWinNums(int a[],int n)
{int i;
bool dup=true;
for(i=0;i<n;i++)
   {while(dup)
     {
      a[i]=rand()%40+1;
      dup=NoDuplicates(a,i,2);
      }
     dup=true;
   }
}
void getLottoPicks(int a[],int n)
{int i;
bool dup=true;
for(i=0;i<n;i++)
   {while(dup)
     {
again: cout<<"Enter number (between 1 and 40) "<<i+1<<": ";
      cin>>a[i];
      if(a[i]<1||a[i]>40)
          {cout<<"number out of range\n";
          goto again;         //easiest to do
          }
      dup=NoDuplicates(a,i,1);
      }
     dup=true;
   }
return;
}
bool NoDuplicates(int a[],int n, int f)
{int i,j;
bool dup=false;
if(n==0)
     return false;
for(i=0;i<=n-1;i++)
     if(a[n]==a[i])
        {dup=true;
           if(f==1)        //from getLottoPicks
           {cout<<"DUPLICATE PICK numbers you've already chosen are:";
            for(j=0;j<n;j++)
                cout<<a[j]<<" ";
            cout<<endl;
            }
        }
return dup;
}
char menu()
{bool legal=false;
char choice,enter;
cout<<"LITTLETON CITY LOTTO MODEL\n";
cout<<"__________________________\n\n";

cout<<"1) Play Lotto\nq) Quit Program\nPlease make a selection:\n";
while(!legal)
{choice=cin.get();
   enter=cin.get();          //get left over trash from buffer
   if(choice=='1'||choice=='q')
      return choice;
    cout<<"Illegal entry - try again\n";
   }
}

Add a comment
Know the answer?
Add Answer to:
java/javafx assignment: Island Paradise just started running their city lotto. You've been tasked with writing a...
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
  • Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements:  The program...

    Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements:  The program should have an array of 5 integers named lottery and should generate a random number in the range of 1 through 99 for each element of the array. The user should enter five digits, which should be stored in an integer array named user. The program is to compare the corresponding elements in the two arrays and keep a count of the digits that...

  • Using the Random, write a simulation that will "play" the California Super LOTTO. Your program logic will allow the player to: 1) Pick any 6 integer numbers from 1 - 70. Your logic should prev...

    Using the Random, write a simulation that will "play" the California Super LOTTO. Your program logic will allow the player to: 1) Pick any 6 integer numbers from 1 - 70. Your logic should prevent the player from selecting a value LESS than 1 or greater than 70. The logic should prevent the player from selecting the SAME number (i.e. they cannot have two or more of their selections be the SAME number). 2) Display the players' 6 number selections...

  • Write a Lottery class that simulates a 6-number lottery (e.g. "Lotto"). The class should have an...

    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 should be a loop that keeps generating random numbers until all 6 numbers are unique.  The Lottery class...

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

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

  • It's writing a simple rock paper scissors game strictly following the instructions. INSTRUCTIONS: If the user...

    It's writing a simple rock paper scissors game strictly following the instructions. INSTRUCTIONS: If the user selects 'p': 1. First the program should call a function named getComputerChoice to get the computer's choice in the game. The getComputerChoice function should generate a random number between 1 and 3. If the random number is 1 the computer has chosen Rock, if the random number is 2 the user has chosen Paper, and if the random number is 3 the computer has...

  • Use C++. In this project you will be tasked with writing a program to play a...

    Use C++. In this project you will be tasked with writing a program to play a guessing game between another player and your program. Your program will start by initializing an array to 5 fixed values in the ranges of 1-1000 in the array. These values should also be in order (sorted). Your program will then begin by asking the player to make a guess from 1-1000. For the first guess of the user, your program will only tell the...

  • c++ can use if else, loop,function ,array,file i.o. Can not use swtich, global variables etc..   Please...

    c++ can use if else, loop,function ,array,file i.o. Can not use swtich, global variables etc..   Please do all parts. previously I post 3 time for part1 ,2 and 3 but I can't make it into one complete program code. I even try to post a questions ask and post the 3 parts of code for experts to put it together. But experts said it's not enough information. please help... Thank you ! Program Objectives: Allow students to create arrays Allow...

  • Hey guys, I need help writing a Tic-Tac-Toe game programmed in Java. The game has to...

    Hey guys, I need help writing a Tic-Tac-Toe game programmed in Java. The game has to be a 1D (One-Dimension) array board NOT 2D. It has to be a human plays against the computer type of Tic-Tac-Toe. Here is the requirements for the program. PLEASE NO COPY AND PASTE ANSWER. Thank you in advance! You will develop a program in which a human plays against the computer. 1. Validate user input at every opportunity. a. Do not allow number entries...

  • Introduction Write a MIPS program to allow a user to play a simple variation of the...

    Introduction Write a MIPS program to allow a user to play a simple variation of the game BINGO. Your program should display the following game board and the player wants to choose a location to mark BINGO A position can be marked by entering its column letter (eit B', 'I', 'N' 'G', or CO and row number (either 1, 2, 3, 4, or 5). An 'X' should mark the positions already marked. An underscore, e C 1 should represent unmarked...

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