1 Replies - 2411 Views - Last Post: 28 January 2011 - 10:15 PM Rate Topic: -----

#1 Guest_EthanWawrynovic*


Reputation:

Lottery Application Problem

Posted 28 January 2011 - 07:21 PM

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.

I know something in my class is messed up. I'm just having a lot of trouble.

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

class Lottery
{

	public int numMatching(int[] userPicks) {
		
		return 0;
	}

	public int[] copy() {
	
		return null;
	}

}

public class WawrynovicLottery
{
   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();
   
      System.out.println("Number of matching digits: " +
                         matching);
      if (matching == 5)
         System.out.println("GRAND PRIZE WINNER!!!!");
   }
}




Is This A Good Question/Topic? 0

Replies To: Lottery Application Problem

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,471
  • Joined: 27-December 08

Re: Lottery Application Problem

Posted 28 January 2011 - 10:15 PM

Your Lottery class doesn't do anything. That's why you are experiencing problems. You just have filler code for those two methods in that class.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1