// Number generation gane by A Thatcher
// uses arrays , random numbers and decision making
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.text.*;
public class Application1
{
public Application1()
{
String input;
String numPick[]=new String[10];
int luck[]=new int[10];
int random[]=new int[10];
int num,temp,yes,x=0,count=0,hitCount=0,missCount=0;
//user chooses number of
integers he wishes to pick
input=JOptionPane.showInputDialog("How
many numbers do you
wish
to pick (1-10)?");
num=Integer.parseInt(input);
if (num>10)
// if num > than 10, user must rechoose
input=JOptionPane.showInputDialog("How
many numbers do you wish to pick
(you cannot choose more than 10)?");
num=Integer.parseInt(input);
if(num==0)
{
//if num is 0, user gets fairwell message, application exited
JOptionPane.showMessageDialog(null, "Thank you. Pleas play
again.");
System.exit(0);
}
temp=num-1;
do
{
count++; // input integers; put
chosen integers into string array
numPick[x]=JOptionPane.showInputDialog("Enter
pick # "+count+
". You may pick any number through 25.");
luck[x]=Integer.parseInt(numPick[x]);
//convert input[](string) to luck[] (int)
//if
choice is greater than 25, user rechooses
if(luck[x]>=26)
numPick[x]=JOptionPane.showInputDialog("Enter pick # "+count+
". Make sure your pick does not exceed 25!!");
luck[x]=Integer.parseInt(numPick[x]);
random[x]=1+(int) (Math.random()*25);
//choose random integer and put into
array
temp--;
x++;
}while(temp>=0);
temp=num-1;
x=0;
do
//compare input integers to random integers
{
yes=0;
for(int
a=0;a<10;a++)
{
if(luck[x]==random[a])yes++;
}
if(yes>=1)hitCount=hitCount+yes;
//add number luck[x] hit to hitCount
else
missCount++; //add one to missCount if luck[x] didn't hit any of
random[]
temp--;
x++;
} while (temp
>=0);
//show number guessed right and wrong
JOptionPane.showMessageDialog(null,"Your guessed "+hitCount+"
right, and "+missCount+" wrong.");
}
public static void main (String args[])
{
Application1 app=new Application1();
System.exit(0);
}
}