I am still a newbie to java, however i managed to do the main algorithms as i did C++ and the programming language is very similar. I havent been taught how to create the gui aspects very well and every search i put into google doesnt make sense to me.
The bit im stuck on states the class should display a logo, a button and a text box to contain the six numbers. The numbers should only be generated when the button is pressed.
This is my code so far
import java.util.*;
public class LotteryNumbers
{
int[] LotteryNumbers = new int[49];
int i;
Random rgen = new Random();
//Creating an Array of 50 integers
public void createNumbers()
{
for (i=0; i < LotteryNumbers.length; i++)
{
LotteryNumbers[i] = i + 1;
}
}
//Shuffling the numbers in the array
public void shuffleNumbers()
{
for (int j=0; j < LotteryNumbers.length; i++)
{
int randomPosition = rgen.nextInt(LotteryNumbers.length);
int temp = LotteryNumbers[j];
LotteryNumbers[j] = LotteryNumbers[randomPosition];
LotteryNumbers[randomPosition] = temp;
}
}
//Sorting the numbers in the array
public void sortNumbers()
{
for(int i=0; i < LotteryNumbers.length-1; i++)
{
for(int j=0; j < LotteryNumbers.length-1-i; j++)
{
if(LotteryNumbers[j] > LotteryNumbers[j+1])
{
int temp = LotteryNumbers[j];
LotteryNumbers[j] = LotteryNumbers[j+1];
LotteryNumbers[j+1] = temp;
}
}
}
}
// Printing the numbers out
public void printnumbers( int j, int [] LotteryNumbers)
{
for (j = 0; j<= 6 && j >= 1; j++)
{
System.out.println("Lotto number: " + j + ":" + LotteryNumbers);
}
}
}

New Topic/Question
Reply



MultiQuote





|