Question: Advanced Java Lottery Program 350 points (final project) Due Date April 22 (no late assignments accepted) You are to write a lottery program to simulate

Advanced Java Lottery Program 350 points (final project)

Due Date April 22 (no late assignments accepted)

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!