Hi, I'm making a Lottery simulator and really need help. These are the specifications (scroll for code):
Hi, I would like to make a Java lottery simulator. This one is different than most, however. The program requirements are:

1) The patron enters his/her 6 chosen numbers (from the numbers 1 through 42 without duplicates) on the keyboard at the appropriate prompt(s). This same, single set of numbers will be used as the patron’s numbers throughout this simulation. It is as if the patron plays the same numbers every week (Jack tells us that this is a common occurrence). We will be testing this set of numbers against a year’s worth of computer-generated picks.

2) For each lottery drawing (one for each Wednesday and Saturday drawing for 52 weeks) in your simulation, the computer must randomly pick and display an initial 6 numbers followed by a 7th number, called the bonus number. The possible random numbers (integers) are 1 through 42. You may not have duplicates!

3) Test your pick, display the year’s worth of picks along with the following counts. Count the number of occurrences of each of the patron’s numbers during the year. For example, it the patron's picks are 1 3 35 4 12 6, your program should print the number of times the computer chose a 1, how many 12s etc. Also, if the patron wins the jackpot, display an appropriate message beside the winning set of numbers as well as reporting the total count of jackpots won (if none, report 0 jackpots) during the year. Note that only exact matches of the original 6 numbers qualify for the Jackpot (order does not matter); the bonus number is not included for this prize.

4) You must use an application-style program (not an applet), Math.random for random number generation, and java.util.ArrayList<E> to “hold” and manipulate most of your data. Your ArrayList needs to specify an appropriate data type for E. You must also use one "regular" array for use as counters (holding ints).

5) Your program must reflect a modular design using multiple methods. Each method needs to be commented.

Here is my code, keep in mind that I am a beginner and my code may not be the greatest. My code will not print anything out and I feel like I've spent too much time on it to give up. I also need help creating array lists for this.
THANK YOU!

Code (methods) :

import java.util.Scanner;

public class megaa
{
public static int[] sameNum  = new int[43];


    public static int[] getNum()


    {


        int[] Rannumbers = new int[7];

        for(int i = 0; i < 7; i++)

        {

            Rannumbers[i] = (int)(Math.random()*42+1);
        }



        for(int num3 = 0; num3 <= 6; num3 ++)

        {


            for(int num4 = 0; num4 <= 6; num4 ++)
            {
                while ( num3 != num4 && Rannumbers[num3] == Rannumbers[num4])
                {



                    Rannumbers[num3] = (int)(Math.random()*42+1);


                 }
             }
        }

        return Rannumbers;
    }



    public static int[] enterNumbers()
    {


        Scanner scan = new Scanner(System.in);


        int[] Playnumbers = new int[6];

        for(int j = 0; j > 6; j ++)
        {   
            System.out.println("Enter the " + (j + 1) + " number: ");


            Playnumbers[j] =  scan.nextInt();
        }

        return Playnumbers;
    }


    public static boolean compareNum(int[] Playnumbers, int[] Rannumbers)
    {
        int num2 = 0;
        for(int num = 0; num < 6; num ++)
        {
            if(Playnumbers[num]==(Rannumbers[num]))


            {
              num2 ++; 
            }
            else


            {
                for(int num1 = 1; num1 < 6; num1++)
                {

                  if(Playnumbers[num] == Rannumbers[num1])
                  {
                      num2 ++;
                    }
                }
            }
        }
        if(num2 == 6)
         { 
             return true;
            }
         else 
         {
             return false;
            }

        }

        public static int[] numEql(int[] Playnumbers, int[] Rannumbers)
         { 
             int [] sameNum = new int [43];




             for (int num3 =0; num3 < 6; num3++)


                {
                    for (int num4 = 0;  num4 < 7; num4++)
                      {
                          if(Playnumbers[num3] == Rannumbers[num4]) 
                            sameNum[Playnumbers[num3]]++;
                        }
                    }
                    return sameNum;


        }
    }

Other part:

import java.util.Scanner; 
public class megabucks
{ 
    public static void main(String[] args)
{  

       Scanner waffles = new Scanner(System.in); 
       boolean w;


       int[] Playnumbers = new int[6];

       int[] Rannumbers = new int[7];

       int[] sameNum = new int[6];








       Playnumbers = megaa.enterNumbers();

       for (int y = 104; y > 0; y++)
       {
           Rannumbers = megaa.getNum(); 
           w = megaa.compareNum(Playnumbers   , Rannumbers   ); 

           if (w == true)



            {   
                System.out.println("You win");



                System.out.println(Playnumbers);
            }
           megaa.numEql(Playnumbers, Rannumbers);
           sameNum = megaa.sameNum;

        }

        for(int numm = 0; numm < 43; numm++)
           {
               if(sameNum[numm]!=0)
               {
                   System.out.println(numm + "appeared" + sameNum[numm]);


    }
}
}
}

You seem to mix up the <..> signs. For example, in your enterNumbers() method, your for loop never runs(simple debugging using System prints told me this). You have the wrong sign in the loop's definition, it should run until it is less than the length of the array, not greater than(it will never run). Without looking at your code in detail, I do not know if this is your only problem, you may well have done the same thing elsewhere, just be careful!

So, your code:

public static int[] enterNumbers()
{


Scanner scan = new Scanner(System.in);


int[] Playnumbers = new int[6];

for(int j = 0; j > 6; j ++)//this should be j < 6 (or j < Playnumbers.length)
{ 
System.out.println("Enter the " + (j + 1) + " number: ");


Playnumbers[j] = scan.nextInt();
}

return Playnumbers;
}

I would advise using array.length when iterating the length of an array, instead of the actual size. In your compare method for example, it would be much more efficient if the code ran the length of an array that is passed in, therefore you would not need to know its specific size.

edit: Just so you can see how easy debugging is, here is how I tested your method

public static int[] enterNumbers()
{
System.out.println("inside enternumbers: ");


		Scanner scan = new Scanner(System.in);


		int[] Playnumbers = new int[6];
		System.out.println("After array declaration");

		for(int j = 0; j < Playnumbers.length; j ++)
		{
		System.out.println("Enter the " + (j + 1) + " number: ");


		Playnumbers[j] = scan.nextInt();
		}

		return Playnumbers;
}

Doing this, I realised it was entering the method, and the code stopped executing at the for loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.