error message cannot find constructor lottery(int[])

import java.util.Random;

public class Lottery
{


   private final int NUM_DIGITS = 5;





   private int[] lotteryNumbers = new int[NUM_DIGITS];



    private int[] userNumbers;
    private int matches;


    public int[] getLottery(int[] l)
    {
        // Create an array the length of l.
        lotteryNumbers = new int[5];

        // Random object.
        Random rand = new Random();

        //Defines elements of l. Copy elements from l to lotteryNumbers.
        for (int i = 0; i < 5; i++)
            {
            lotteryNumbers[i] = rand.nextInt(9);
            lotteryNumbers[i] = l[i];
            }
        return lotteryNumbers;
    }


    public int[] getUser(int[] u)
    {
        // Create an array the length of l.
        userNumbers = new int[5];


        //Defines elements of l. Copy elements from l to lotteryNumbers.
        for (int i = 0; i < 5; i++)
            userNumbers[i] = u[i];
        return userNumbers;
    }
    public int getMatches()
    {
        matches = 0;
        for (int i = 0; i < 5; i++)
        {
            if (userNumbers[i] == lotteryNumbers[i])
                matches = matches + 1;
            else
                matches = matches + 0;
        }
        return matches;
    }
}

.

import java.util.Scanner;

public class Lotto
{
    public static void main(String[] args)
    {


        final int NUMBERS = 5;

        int[] winNumbers = new int[NUMBERS];
        int[] userNumbers = new int[NUMBERS];
        int matches;

        Scanner keyboard = new Scanner(System.in);

        Lottery lot = new Lottery(userNumbers);


        for (int i = 0; i < NUMBERS; i++)
        {
            System.out.print("Number " + (i + 1) + ": ");
            userNumbers[i] = keyboard.nextInt();
            lot.getUser(userNumbers);
        }
        for (int h = 0; h < NUMBERS; h++)
        {
            matches = lot.getMatches();
        }

        System.out.println("The winning numbers are:");
        for (int j = 0; j < NUMBERS; j++)
        {
            lot.getLottery(winNumbers);
            System.out.print(winNumbers[j] + "\t");
        }
        System.out.println("\n");
        if (matches == 5)
            System.out.println("You are a grand prize winner!");
        else
            System.out.println("You matched " + matches + " out of 5 numbers. Better luck next time.");
    }


}

Recommended Answers

All 3 Replies

That is because you haven't defined such a constructor in your Lottery class.

Come on you could have figure that out. Put some effort into it

i tried to make lotteryNumber private but it says already defined in the class. so i am stuck

That has nothing to do with trying to use a class constructor that does not exist, which is what you are doing right here

Lottery lot = new Lottery(userNumbers);

If you make changes to the code, repost it using [code]

[/code] tags, because it's just a mess with all the formatting removed.

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.