Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 14th, 2009, 01:05 PM
sunlight18 sunlight18 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 3 sunlight18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 50 sec
Reputation Power: 0
Post 2-d array with lottery ticket numbers

I need help with my program...it's main goal is to
- allow the user to input the number of lottery tickets they want
- use the number of tickets and generate (6)random numbers and return them in a two dimensional array with a ticket per row
- 6 numbers in a row and 6 colums

for example if the user enters "1" as the tickets they want, the out put should be

Code:
your tickets are:
1 2 3 8 5 6 



this is what i have so far but it is not working so please help..i need it to print out and also to generate the unique numbers


Code:
public static void main(String[] args) {
		// Create Scanner
		Scanner number = new Scanner(System.in);

		// prompt the user to number of tickets
		System.out.println("Please indicate how many tickets you want to generate?");
		int numentered = number.nextInt();
		System.out.println(numentered );
	}

	public static int[][] generateLottoTickets(int num) {
int [][] tic=new int[num][6];
				                                
		for(int x=0; x<num; x++){
			int numInTicket=0;
			while(numInTicket<6){//go till 6 numbers are in a ticket
		
		//generate lottery numbers
		int rand=(int)(Math.Random*49);
		rand++;//count only from 1-49
		
		
		}
		return tic;
	}

}

Reply With Quote
  #2  
Old November 14th, 2009, 02:22 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
I would suggest methods like these (I haven't tested them, but they should at least get you started):

For generating the lotto tickets:
Code:
public static int[][] generateLottoTickets( int number )
{
    int row, column;
    int [][] ticketArray = new int[number][6];
    java.util.Random random = new java.util.Random();
    for( row = 0; row < number; row++ )
    {
        for( column = 0; column < 6; column++ )
        {
            ticketArray[row][column] = random.nextInt( 10 );
        }
    }
    return ticketArray;
}

Note the above statement random.nextInt( 10 ); This generates a random integer from 0 (inclusive) to 10 (exclusive). Simply insert your own value here if you want a greater range of numbers than 0-9.

Then, for printing the lotto tickets:
Code:
public static void printTickets( int[][] ticketArray, int number )
{
    int row, column;
    String columnString;
    System.out.println( "your tickets are:" );
    for( row = 0; row < number; row++ )
    {
        rowString = "";
        for( column = 0; column < 6; column++ )
        {
            rowString = rowString + ticketArray[row][column] + " ";
        }
        System.out.println( rowString );
    }
}


Hope this helps. Let me know if something needs further clarification.
Comments on this post
sunlight18 agrees!

Reply With Quote
  #3  
Old November 14th, 2009, 02:37 PM
sunlight18 sunlight18 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 3 sunlight18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 50 sec
Reputation Power: 0
Post

Quote:
Originally Posted by paulscode
I would suggest methods like these (I haven't tested them, but they should at least get you started):

For generating the lotto tickets:
Code:
public static int[][] generateLottoTickets( int number )
{
    int row, column;
    int [][] ticketArray = new int[number][6];
    java.util.Random random = new java.util.Random();
    for( row = 0; row < number; row++ )
    {
        for( column = 0; column < 6; column++ )
        {
            ticketArray[row][column] = random.nextInt( 10 );
        }
    }
    return ticketArray;
}

Note the above statement random.nextInt( 10 ); This generates a random integer from 0 (inclusive) to 10 (exclusive). Simply insert your own value here if you want a greater range of numbers than 0-9.

Then, for printing the lotto tickets:
Code:
public static void printTickets( int[][] ticketArray, int number )
{
    int row, column;
    String columnString;
    System.out.println( "your tickets are:" );
    for( row = 0; row < number; row++ )
    {
        rowString = "";
        for( column = 0; column < 6; column++ )
        {
            rowString = rowString + ticketArray[row][column] + " ";
        }
        System.out.println( rowString );
    }
}


Hope this helps. Let me know if something needs further clarification.


what is rowstring? and it's not declared...

Reply With Quote
  #4  
Old November 14th, 2009, 05:04 PM
paulscode's Avatar
paulscode paulscode is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Location: Fort Meade, MD
Posts: 86 paulscode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 37 sec
Reputation Power: 11
Quote:
Originally Posted by sunlight18
what is rowstring? and it's not declared...

Sorry, it seems I wrote two different names for that string (rowString or columnString). The basic concept is to start with an empty string, then append each number in a row to it, and then print the contents.
Comments on this post
sunlight18 agrees!

Reply With Quote
  #5  
Old November 15th, 2009, 09:49 PM
sunlight18 sunlight18 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 3 sunlight18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 50 sec
Reputation Power: 0
Thumbs up Thanks

thanks,
you really helped me. It works.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > 2-d array with lottery ticket numbers


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap