Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need some help with Lottery Program, Final Project.... Here is the project specs... You are to write a lottery program to simulate the pick four

Need some help with Lottery Program, Final Project....

Here is the project specs...

You are to write a lottery program to simulate the pick four lottery. This is a game where the user will pick four numbers (between 1 and 40 inclusive) and the computer will generate four random numbers (between 1 and 40 inclusive). Depending on how many numbers that are matched, a dollar prize will be awarded according to the following: Match 4 numbers $500,000 prize Match 3 numbers $50,000 prize Match 2 numbers $1,000 prize Match 1 number $100 prize The specifications of the project are as follows: You must have user defined classes within the code. Code done in only one main method will not be accepted You may use any data structure that you like Additionally: You must have code to check that the user has entered an integer You must have code to check that the user has entered 4 unique integers You must have code to check that the user has entered 4 numbers under 41 Keep asking for input until all rules in steps 1,2 and 3 above have been met and 4 unique numbers under 41 are entered Create code to check that the computer has entered 4 unique numbers Create code to check if any numbers were matched and print the results Create code to award the monetary prize (if any is due) and print the award Create code to play until the user wants to stop. You must make sure the user can enter capital or lower case letters to allow the game to be played again. For example, if you are asking the user to enter yes , your program must be user friendly and accept any combination of capital of lower case letters such as yes, YES, Yes, yES, yeS (hint:you could use a Java string function to change the input to all lower case) Create code to determine how many numbers the user entered matched the computer numbers (1,2,3,or 4 numbers matched) Create code to calculate and print: How many games were played How many times 0 numbers were matched How many times 1 numbers were matched How many times 2 numbers were matched How many times 3 numbers were matched How many times 4 numbers were matched Percent of times the user matched 0 numbers Percent of times the user matched 1 numbers Percent of times the user matched 2 numbers Percent of times the user matched 3 numbers Percent of times the user matched 4 numbers How much money was won Copy your code and a screen print of it running at least 10 times to word and upload your document to blackboard Note: You will have to investigate and implement code to: Read in a character and check if it can be converted to an integer Generate a random number between 1 and 40

This is what I have: Please help...

package Final_Project;

import java.text.DecimalFormat;

import javax.swing.JOptionPane;

public class Final_Project

{

public static void main(String[] args)

{

int i;

lottery num[] = new lottery[40];

for (i = 0; i<=39; i++)

{

num[i] = new lottery();

}

lotto value=new lotto();

value.load(num);

value.pick4(num);

value.final_output(num);

System.exit(0);

}

}

class lotto

{

int i;

int zerocount;

int onecount;

int twocount;

int threecount;

int fourcount;

int games;

int moneywon=0;

int moneyoverall=0;

double zeropercent, onepercent, twopercent, threepercent, fourpercent;

int [] lottery_value;

String [] lottery_number;

int [] your_value;

String your_number;

String play_again = "yes";

String formatpercentzero;

String formatpercentone;

String formatpercenttwo;

String formatpercentthree;

String formatpercentfour;

DecimalFormat d2f =new DecimalFormat("#00.##");

String printing=" ";

void load(lottery num[])

{

for (i=0;i<=39;i++);

{

num[i].value= i+1;

num[i].used = false;

}

}

void pick4(lottery num[])

{

int k;

for (i=0; i<=3; i++)

{

your_number= JOptionPane.showInputDialog(null, "What number would you like?","Pick between 1 and 40",JOptionPane.QUESTION_MESSAGE);

your_value[i]=Integer.parseInt(your_number);

}

for (k=0; k<=39; k++)

{

num[i].used = true;

}

while ((play_again.equals("yes"))||((play_again.equals("Yes"))||((play_again.equals("yEs"))||((play_again.equals("yES"))||((play_again.equals("yeS"))||((play_again.equals("YeS"))))))))

{

games=games+1;

}

}

void final_output(lottery num[])

{

printing="";

printing=printing+"You lottery numbers: "+your_number+" ";

printing=printing+"======================================="+" ";

printing=printing+"The number of games played = "+games+" ";

printing=printing+"Amount won = "+moneyoverall+" "+" ";

printing=printing+"The number of games with 0 matches = "+zerocount+" ";

printing=printing+"The number of games with 1 matches = "+onecount+" ";

printing=printing+"The number of games with 2 matches = "+twocount+" ";

printing=printing+"The number of games with 3 matches = "+threecount+" ";

printing=printing+"The number of games with 4 matches = "+fourcount+" ";

zeropercent=zerocount*1.0/games;

onepercent=onecount*1.0/games;

twopercent=twocount*1.0/games;

threepercent=threecount*1.0/games;

fourpercent=fourcount*1.0/games;

formatpercentzero=d2f.format(zeropercent*100);

formatpercentone=d2f.format(onepercent*100);

formatpercenttwo=d2f.format(twopercent*100);

formatpercentthree=d2f.format(threepercent*100);

formatpercentfour=d2f.format(fourpercent*100);

printing=printing+"The percentage of games won with 0 matches = "+formatpercentzero+"%"+" "+" ";

printing=printing+"The percentage of games won with 1 matches = "+formatpercentone+"%"+" "+" ";

printing=printing+"The percentage of games won with 2 matches = "+formatpercenttwo+"%"+" "+" ";

printing=printing+"The percentage of games won with 3 matches = "+formatpercentthree+"%"+" "+" ";

printing=printing+"The percentage of games won with 4 matches = "+formatpercentfour+"%"+" "+" ";

JOptionPane.showMessageDialog(null,

printing,"Lotto",JOptionPane.INFORMATION_MESSAGE);

}

}

class lottery

{

int value;

boolean used;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

Students also viewed these Databases questions

Question

=+ For what reasons can and do unions go on strike?

Answered: 1 week ago