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!

em ... try help you with what? ok, you've stated what you want your application to do, but you haven't told us what it does do...
does it give you an error message?, does it run, but give a different output than you expect? does it fail to compile?

...

the answers to these questions would help us a lot. we're not just going to look over every line of your code to check if we may pick up on any problems, since we wouldn't even know whether or not that is related to the problem you (think) you're having.

if you get an error message, show it here, and tell us when you get this. on compilation, on running the application, ...

Yes,it run but I want to have more in output.I expect that after I choose number and print the result at the first time,my program will ask the player:"Do you want to continue until you win or not?".If the player say no,program will stop;if he says yes,program will run until player win.

....


I also program until find the player win.and I don't know to program like above.Please help me!

yes, I now understand you want more than what you get, but what is it you get?

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]

ABOVE IS MY OUTPUT,AND I WANT TO ASK THE PLAYER BEFORE THE PROGRAM CONTINUE RUNNING UNTIL FIND THE ROW WHICH PLAYER WIN.

I WANT LIKE THIS:

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 until you got winning?(Y/N):

IF PLAYER CHOOSE Y,PROGRAM WILL CONTINUE RUNNING LIKE THAT.

Row 1 do not win and good luck for the next time !
Row 2 do not win and good luck for the next time !
The winning numbers are [17, 10, 37, 21, 33, 3, 6]
The extra numbers are [23, 9, 13]

Row 1 do not win and good luck for the next time !
Row 2 do not win and good luck for the next time !
The winning numbers are [5, 23, 36, 12, 13, 8, 4]
The extra numbers are [21, 38, 20]

Row 1 do not win and good luck for the next time !
Row 2 do not win and good luck for the next time !
The winning numbers are [17, 10, 37, 21, 33, 3, 6]
The extra numbers are [23, 9, 13]

Row 1 do not win and good luck for the next time !
Row 2 do not win and good luck for the next time !
The winning numbers are [5, 23, 36, 12, 13, 8, 4]
The extra numbers are [21, 38, 20](NOTE:IT RUN LOOP MANY TIMES UNTIL FIND THE WINNING NUMBER)


IF PLAYER CHOOSE N,PROGRAM WILL STOP.

well ... you can implement somethinglike:

boolean repeat = false;

do{

printNLines();
if ( !repeat ){
  repeat = doYouWantToContinue();
}

} while(repeat && !gameWon);

Thanks in advanced,can you show me clearly where I need to put this syntax because it really important for me.I need to completed it before tomorrow morning.And if I can have this output.My program will be completed.Please help me.

well .. can't you try to implement it yourself?
honestly, if you have to turn it in tomorrow, you propably were aware of this assignment before today.

Your teacher will also expect you to be able to do so. just give it a try, and if you can't get it to work, then show what you've tried.

at this point: no, I don't have your code here. no, I wasn't planning on running it localy, nor learning all the details of it.

I've shown you all you need to get it to work, and you (should) know your code a lot better than I do.

also, a few VERY important reasons:
1. if I were to implement it, and make a tiny mistake, just because I don't know the expected outcome as well as you do, you might lose points because of it.
2. if I implement it, and you hand it in, that could be looked at as cheating, and you might pass your caurse based on work you didn't do yourself, maybe don't even know how to do yourself. that way, if you go to job interviews, you might make it harder for those who do know and understand.

I tried it but it still not work like I want.:-(

well .. I've taken a quick peek.. I think you'll need to change your logic somewhat.
checkWin should return true for the entire collection, the call to the method should not be placed within a for-loop.

of course you could add an "if then break out of the loop" within the for-loop, but that doesn't look like the best way to go to me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.