package lottery;
import java.util.*;
import java.util.ArrayList;
public class Lottery {
public static final int REGULAR_NUMBERS = 7;
public static final int EXTRA_NUMBERS = 3;
public static final int MAX_NUMBER = 39;
public static final int TOTAL_PRIZE = 50;
public static double winning;
public static double cost;
public static int round;
public static int rows;
public static ArrayList<Integer> regularNumbers;
public static ArrayList<Integer> extraNumbers;
public static ArrayList<ArrayList<Integer>> lottery;
public static Boolean flagContinue = true;
// public static Boolean flagLoop = false;
public static void main(String[] args) {
cost = 0;
round = 1;
rows = 0;
boolean flag = true;
Scanner reader = new Scanner(System.in);
regularNumbers = createRegularNumbers();
extraNumbers = createExtraNumbers(regularNumbers);
while(flag){
System.out.println("How many row do you want (€0.8 per rows) :");
rows = reader.nextInt();
if (rows < 20 && rows >= 1) {
flag = true;
cost = 0.8 * rows;
} else {
flag = false;
}
// ArrayList<ArrayList> rowList = new ArrayList<ArrayList>();
if (flag == true) {
System.out.println("You chose " + rows + " rows");
System.out.printf("It costs you : %.1f € \n", cost);
System.out.println("Your round : " + round);
System.out.println();
lottery = getNumbers();
System.out.println();
//ArrayList<Integer> regular = regularNumbers;
//ArrayList<Integer> extra = extraNumbers;
for (int j = 0; j < rows; j++) {
System.out.println("Your numbers for row " + (j + 1) + " are: " + lottery.get(j));
}
System.out.println("The winning numbers are "
+ regularNumbers);
System.out.println("The extra numbers are "
+ extraNumbers);
System.out.println();
for (int i = 0; i < lottery.size(); i++) {
checkWin((ArrayList<Integer>) lottery.get(i), regularNumbers, extraNumbers,false,(i+1));
}
while(flagContinue)
{
System.out.println("The winning numbers are "
+ regularNumbers);
System.out.println("The extra numbers are "
+ extraNumbers);
System.out.println();
regularNumbers = createRegularNumbers();
extraNumbers = createExtraNumbers(regularNumbers);
for (int i = 0; i < lottery.size(); i++) {
checkWin((ArrayList<Integer>) lottery.get(i), regularNumbers, extraNumbers,true,(i+1));
}
}
System.out.println("Round until you win category 1 : "+round);
System.out.println("Cost until you win category 1 : "+cost);
System.out.println("Wining money until you win category 1 : "+winning);
flag=false;
}
else
{
System.out.println("You can only have maximum 20 rows.Please type again!");
}
}
}
public static void display(String something,Integer rowIndex) {
System.out.println("Row " + (rowIndex) + something);
}
public static ArrayList<Integer> createRegularNumbers() {
ArrayList<Integer> regularNumber = new ArrayList<Integer>();
Random r = new Random();
Integer number = 0;
while (regularNumber.size() < REGULAR_NUMBERS) {
number = r.nextInt(MAX_NUMBER) + 1;
if (!regularNumber.contains(number)) {
regularNumber.add(number);
}
}
return regularNumber;
}
public static ArrayList<Integer> createExtraNumbers(ArrayList<Integer> regularNumbers) {
ArrayList<Integer> extraNumber = new ArrayList<Integer>();
Random r = new Random();
Integer number = 0;
while (extraNumber.size() < EXTRA_NUMBERS) {
number = r.nextInt(MAX_NUMBER) + 1;
if (!regularNumbers.contains(number) & !extraNumber.contains(number)) {
extraNumber.add(number);
}
}
return extraNumber;
}
public static ArrayList<ArrayList<Integer>> getNumbers() {
ArrayList<ArrayList<Integer>> rowList = new ArrayList<ArrayList<Integer>>();
ArrayList<Integer> value = null;
Scanner console = new Scanner(System.in);
for (int j = 0; j < rows; j++) {
value = new ArrayList<Integer>();
int errorCode = 0;
while(true)
{
Boolean flagLoop = false;
System.out.print("Choose your " + REGULAR_NUMBERS
+ " numbers for row " + (j + 1) + ":");
while (value.size() < REGULAR_NUMBERS) {
int number = console.nextInt();
if(value.contains(number) || number == 0 || number >39)
{
flagLoop = true;
errorCode = 1;
break;
}
value.add(number);
}
if(flagLoop && errorCode ==1)
{
System.out.println("You can choose different number from 1 to 39 for one row, please type again !");
value.clear();
continue;
}
else
break;
}
rowList.add(value);
}
return rowList;
}
public static void checkWin(ArrayList<Integer> values,ArrayList<Integer> regularNumbers,ArrayList<Integer> extraNumbers,Boolean calculate, Integer rowIndex) {
if(calculate)
{
round++;
cost += cost;
}
Integer regularMatch = 0;
Integer extraMatch = 0;
for (int i = 0; i < values.size(); i++)
{
Integer value = values.get(i);
for (int j = 0; j < regularNumbers.size(); j++) {
if(value == regularNumbers.get(j))
{
regularMatch++;
}
}
}
for (int i = 0; i < values.size(); i++)
{
Integer value = values.get(i);
for (int j = 0; j < extraNumbers.size(); j++) {
if(value == extraNumbers.get(j))
{
extraMatch++;
}
}
}
if (regularMatch == 7) {
// System.out.println("Row " + rows + " win category 1 !");
display("win category 1",rowIndex);
winning += 0.136 * TOTAL_PRIZE;
System.out.printf("Your prize is %.1f € \n", winning);
flagContinue = false;
}
if (regularMatch == 6 & extraMatch == 1) {
// System.out.println("Row " + rows + " win category 2 !");
display("win category 2",rowIndex);
winning += 0.000521 * TOTAL_PRIZE;
System.out.printf("Your prize is %.1f € \n", winning);
}
if (regularMatch == 6 & extraMatch != 1) {
// System.out.println("Row " + rows + " win category 3 !");
display("win category 3",rowIndex);
winning += 0.000612 * TOTAL_PRIZE;
System.out.printf("Your prize is %.1f € \n", winning);
}
if (regularMatch == 5) {
// System.out.println("Row " + rows + " win category 4 !");
display("win category 4",rowIndex);
winning += 0.000212 * TOTAL_PRIZE;
System.out.printf("Your prize is %.1f € \n", winning);
}
if (regularMatch == 4) {
// System.out.println("Row " + rows + " win category 5 !");
display("win category 5",rowIndex);
winning += 0.0000456 * TOTAL_PRIZE;
System.out.printf("Your prize is %.1f € \n", winning);
} else {
//System.out.println("Row "+rows+" do not win and good luck for the next time !");
display(" do not win and good luck for the next time !",rowIndex);
}
}
}
Now I want to have like that:
How many row do you want (€0.8 per rows) :
2
You chose 2 rows
It costs you : 1.6 €
Your round : 1
Choose your 7 numbers for row 1:1 2 3 4 5 6 7
Choose your 7 numbers for row 2:2 6 9 8 7 4 1
Your numbers for row 1 are: [1, 2, 3, 4, 5, 6, 7]
Your numbers for row 2 are: [2, 6, 9, 8, 7, 4, 1]
The winning numbers are [21, 19, 30, 34, 2, 5, 22]
The extra numbers are [8, 9, 23]
Do you want to continue:(Y/N)
If the player say yes,it will run like I did. but if they say no,this program will stop
Please help me as soon as possible! I try my best but I can't do anything!