import java.util.Scanner;
import java.util.Random;

class Lottery

public class LotteryDemo
   public static void main(String[] args)
      int[] userPicks = new int[5];
      int matching;

       // Create a Scanner object for keyboard input.
      Scanner keyboard = new Scanner(System.in);

      // Create a Lottery object.
      Lottery lotto = new Lottery();

      // Get the user's picks.
      for (int digit = 1; digit <= 5; digit++)
         System.out.print("Enter digit " + digit + ": ");
         userPicks[digit-1] = keyboard.nextInt();
         while (userPicks[digit-1] < 0 || userPicks[digit-1] > 9)
            System.out.print("ERROR. Enter a single digit (0 - 9): ");
            userPicks[digit-1] = keyboard.nextInt();

      // Compare.
      matching = lotto.numMatching(userPicks);

      // Display the results.
      int[] lottoNums = lotto.copy();
      System.out.print("Lottery numbers: ");
      for (int i = 0; i < lottoNums.length; i++)
         System.out.print(lottoNums[i] + " ");

      System.out.println("Number of matching digits: " +
      if (matching == 5)
         System.out.println("GRAND PRIZE WINNER!!!!");

Edited by mike_2000_17: Fixed formatting

6 Years
Discussion Span
Last Post by Ezzaral

Write a Lottery class that simulates a lottery. The class should have an array of five integers named lotteryNumbers. The constructor should generate a random number in the range of 0 through 9 for each element in the array. Refer to Chapter 4's discussion of the Random class for generating random numbers. The class should also have a method that accepts an array of five integers that represents a person's lottery picks. The method is to compare the corresponding elements in the two arrays and return the number of digits that match. Note that unline the Florida Lotto, the digits must match by position!


So post your code and actually ask a question. This isn't a homework completion service and no one is going to write detailed instructions on how to complete this.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.