package lotto;

import java.util.*;

public class Main {

public static int[] userinput = new int[6];// declaring a new array of chars

public static int[] Computernumber = new int[6];

public static void main(String[] args) {

int money = 40;

int totalcount = 0;

int repeat = 0;

for (; repeat == 0

{

Arrays.fill(userinput, 0);

Arrays.fill(Computernumber, 0);

say("Welcome to The lotto! each game will cost you 5 fun coupons");

for (int array = 0; array < 6; ++array) {

userinput[array] = finduserinput();

}

for (int array2 = 0; array2 < 6; ++array2) {

Computernumber[array2] = findcomputernumber();

say("Random number is : " + Computernumber[array2]);

}

for (int count = 0; count < 6; ++count) {

for (int count2 = 0; count2 < 6; ++count2) {

if (userinput[count] == Computernumber[count2]) {

totalcount = (totalcount + 1);

}

}

}

say("you had " + totalcount + " matches");

if (totalcount < 3) {

say("You have won nothing.");

}

if (totalcount > 4) {

say("You have won one million dollars!");

money = (money + 1000000);

} else {

int randomwin = findrandomwin();

money = (money + randomwin);

}

repeat = askrepeat();

}

}

public static void say(String aMessage) {

System.out.println(aMessage);

}

public static int finduserinput() {

int name = 1;

say("please choose a number between 1 and 40");

try {

Scanner scan1 = new Scanner(System.in);

name = scan1.nextInt();

} catch (InputMismatchException ime) {

say("There was an error in your typing please make sure the value entered is within the set parametres");

finduserinput();

}

if (name > 0 && name < 41) {

} else {

say("That was not a valid number please check your number and try again");

finduserinput();

}

for (int array = 0; array < 6; ++array) {

if (userinput[array] == name) {

say("You cannot repeat your number input please enter another number.");

finduserinput();

} else {

}

}

return name;

}

public static int findcomputernumber() {

Random Rndnumber = new Random();

int RandomNum = Rndnumber.nextInt(7);

for (int array = 0; array < 6; ++array){

if(RandomNum == Computernumber[array]){

findcomputernumber();

}

}

return RandomNum;

}
public static int findrandomwin() {

Random Rnd = new Random();

int Randomwin = Rnd.nextInt(101);

return Randomwin;

}

public static int askrepeat() {

say("you have " + "Fun coupons left would you like to play again?");

int answer = 0;

try {

answer = System.in.read();

System.in.read();

} catch (Exception e) {

say("Error in input");

askrepeat();

}

if (answer == 89 || answer == 121) {

answer = 0;

} else if (answer == 78 || answer == 110) {

answer = 1;

}

return answer;

}

}