SHARE
TWEET

lottogame

a guest Nov 8th, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.         // TODO Auto-generated method stub
  8.         Random rand = new Random();
  9.         int lottoNumbers[] = new int[10];
  10.         // sets array size to 10
  11.         int indexFilled = 0;
  12.         //Get random unique numbers and checks if any repeatead number exist in the array
  13.         while (indexFilled < lottoNumbers.length) {
  14.             int number = rand.nextInt(99) + 1;
  15.             // generates a random number between 1 and 99
  16.             boolean repeated = false;
  17.             for (int indexPosition = 0; indexPosition < indexFilled; indexPosition++) {
  18.                 // checking values add to the array, checking if this number is repetead in the previous values
  19.                 if (lottoNumbers[indexPosition] == number) {
  20.                     repeated = true;
  21.                 }
  22.             }
  23.             //this part it is where the program adds the number to the array if not repeatead.
  24.             if (!repeated) {
  25.                 lottoNumbers[indexFilled] = number;            
  26.                 indexFilled++;
  27.             }
  28.         }
  29.         System.out.print("");
  30.         System.out.print("The lotto numbers for tonight is: ");
  31.         //This for has the fuction to print only
  32.         for(int index =0; index< lottoNumbers.length; index++) {
  33.             if (lottoNumbers[index] < 10) {
  34.                 System.out.print(" " + "0" + lottoNumbers[index]);
  35.                 // checks if number is less than 10 to add the 0 to the left hand side
  36.             } else {
  37.                 System.out.print(" " + lottoNumbers[index]);
  38.             }
  39.         }
  40.         //Sum
  41.         int sum = 0;
  42.         for(int index =0; index< lottoNumbers.length; index++) {
  43.             sum += lottoNumbers[index];
  44.         }
  45.         System.out.println(" ");
  46.         System.out.println("Sum of all lotto number is: "+sum);
  47.         System.out.println("Now the BONUS game starts, You win if the number same number appears more than once");
  48.         //start of the bonus game
  49.         int[] arr={10,20,50,200,1000};
  50.         Random a=new Random();
  51.         int bonus10=0;
  52.         int bonus20=0;
  53.         int bonus50=0;
  54.         int bonus200=0;
  55.         int bonus1000=0;
  56.         for (int indexC=0; indexC <=3; indexC++) {
  57.             float checker = a.nextInt(100);
  58.             // randomize a number
  59.             if (checker < 60) { //percentage checker
  60.                 bonus10++;
  61.                 System.out.println(" "+arr[0]+"€");
  62.             } else if (checker < 80) { //percentage checker
  63.                 bonus20++;
  64.                 System.out.println(" "+arr[1]+"€");
  65.             } else if (checker < 90) { //percentage checker
  66.                 bonus50++;
  67.                 System.out.println(" "+arr[2]+"€");
  68.             } else if (checker < 97.5) { //percentage checker
  69.                 bonus200++;
  70.                 System.out.println(" "+arr[3]+"€");
  71.             } else  {
  72.                 bonus1000++;
  73.                 System.out.println(" "+arr[4]+"€");
  74.             }
  75.         }
  76.         int bonusGamePrize=0;
  77.         if(bonus1000>=2) {
  78.             bonusGamePrize=1000;
  79.             System.out.println("You have won 1000€ on the bonus game");
  80.         } else if (bonus200>=2) {
  81.             bonusGamePrize=200;
  82.             System.out.println("You have won 200€ on the bonus game");
  83.         } else if (bonus50>=2) {
  84.             bonusGamePrize=50;
  85.             System.out.println("You have won 50€ on the bonus game");
  86.         } else if (bonus20>=2) {
  87.             bonusGamePrize=20;
  88.             System.out.println("You have won 20€ on the bonus game");
  89.         } else if (bonus10>=2) {
  90.             bonusGamePrize=10;
  91.             System.out.println("You have won 10€ on the bonus game");
  92.         }
  93.         Scanner in = new Scanner (System.in);
  94.         int userNumberArr[] = new int [5];
  95.         System.out.println("Pick 5 numbers between 1 and 99");
  96.         int index = 0;
  97.         while (index < userNumberArr.length) { //while loop to check if number was typed already and if bigger than 1 or smaller than 99
  98.             int userNumberInput = in.nextInt();
  99.             boolean found = false;
  100.             for (int i=0; i<userNumberArr.length; i++)
  101.                 if (userNumberArr[i]==userNumberInput) {
  102.                     System.out.println("Error!! Number already exist or is bigger than 99 or smaller than 1, Pick another Number:");
  103.                     found = true;
  104.                     break;
  105.                 } else if (userNumberInput>99) {
  106.                     System.out.println("Error!! Number already exist or is bigger than 99 or smaller than 1, Pick another Number:");
  107.                     found=true;
  108.                     break;
  109.                 }
  110.                 else if (userNumberInput<1) {
  111.                     System.out.println("Error!! Number already exist or is bigger than 99 or smaller than 1, Pick another Number:");
  112.                     found = true;
  113.                     break;
  114.                 } else {
  115.                     found = false;
  116.                 }
  117.  
  118.             if (!found) {
  119.                 userNumberArr[index]=userNumberInput;
  120.                 index++;
  121.             }
  122.         }
  123.         // this part below is to check if user found any number
  124.            int winnerChecker=0;
  125.             for(int i = 0;i < 5; i++) {
  126.                 for (int k = 0; k < 10; k++) {
  127.                     if (userNumberArr[i]==lottoNumbers[k]) {
  128.                         winnerChecker++;
  129.                     }
  130.                 }
  131.             }
  132.         int winnerCheckerPrize=0;
  133.         // switch statements to check if user won any amount if he guess correctly any number
  134.         switch (winnerChecker) {
  135.         case 0:
  136.             System.out.println("You haven't guessed any numbers");
  137.             break;
  138.         case 1:  
  139.             winnerCheckerPrize = winnerCheckerPrize + 1000;
  140.             System.out.println("You got 1 Number, You've won 1000 €");
  141.             break;
  142.         case 2:
  143.             winnerCheckerPrize = winnerCheckerPrize + 5000;
  144.             System.out.println("You got 2 Numbers, You've won 5000 €");
  145.             break;
  146.         case 3:
  147.             winnerCheckerPrize = winnerCheckerPrize + 20000;
  148.             System.out.println("You got 3 Numbers, You've won 20,000 €");
  149.             break;
  150.         case 4:
  151.             winnerCheckerPrize = winnerCheckerPrize + 100000;
  152.             System.out.println("You got 4 Numbers, You've won 100,000 €");
  153.             break;
  154.         case 5:
  155.             winnerCheckerPrize = winnerCheckerPrize + 700000;
  156.             System.out.println("You got 5 numbers, You've won 700,000 €");
  157.             break;
  158.         }
  159.         // part of the program that checks and asks user if he guessed any number
  160.         int sumPrize=0;
  161.         System.out.println("Guess the sum of all numbers:");
  162.         int guessSumInput = in.nextInt();
  163.         if(sum==guessSumInput) {
  164.             sumPrize = sumPrize +300000;
  165.             System.out.println("You have won €300,00");
  166.         } else {
  167.             System.out.println("You haven't guessed correctly the sum of all numbers :(");
  168.         }
  169.         // part that checks if user guessed corectly any sequences
  170.         System.out.println(sumPrize);
  171.         boolean foundTwo=false;
  172.         int numberFound = 0;
  173.         for(int i=0;i<=(lottoNumbers.length-userNumberArr.length);i++)
  174.         {
  175.             boolean validator=true;
  176.             for(int j=0;j<userNumberArr.length;j++)
  177.             {  
  178.                 if(userNumberArr[j]!=lottoNumbers[j+i])
  179.                 {
  180.                     validator=false;
  181.                     break;
  182.                 } else {
  183.                     numberFound++;
  184.                 }
  185.             }
  186.             if(validator==true)
  187.             {
  188.                 foundTwo=true;
  189.                 break;
  190.             }
  191.         }
  192.         int numberFoundPrize=0;
  193.         switch(numberFound) {
  194.         case 0:
  195.             System.out.println("You haven't guessed any sequences");
  196.             break;
  197.         case 1:
  198.             System.out.println("You haven't guessed any sequences ");
  199.             break;
  200.         case 2:
  201.             numberFoundPrize=numberFoundPrize+50000;
  202.             System.out.println("You guessed a sequence of two! You have won: €50,000");
  203.             break;
  204.         case 3:
  205.             numberFoundPrize=numberFoundPrize+300000;
  206.             System.out.println("You guessed a sequece of three! Youhave won: €300,000");
  207.             break;
  208.         case 4:
  209.             numberFoundPrize=numberFoundPrize+800000;
  210.             System.out.println("You guessed a sequence of four! You have won: €800,000");
  211.             break;
  212.         case 5:
  213.             numberFoundPrize=numberFoundPrize+3000000;
  214.             System.out.println("You guessed a sequence of five! You have won: €3,000,000");
  215.             break;
  216.  
  217.         }
  218.         int finalPrize=0;
  219.         if (numberFoundPrize>sumPrize&&numberFoundPrize>winnerCheckerPrize) {
  220.             finalPrize=numberFoundPrize+bonusGamePrize;
  221.             System.out.println("You have won the total of:"+finalPrize+"€");
  222.         } else if (sumPrize>numberFoundPrize&&sumPrize>winnerCheckerPrize) {
  223.             finalPrize=sumPrize+bonusGamePrize;
  224.             System.out.println("You have won the total of:"+finalPrize+"€");
  225.         } else if (winnerCheckerPrize>sumPrize&&winnerCheckerPrize>numberFoundPrize)
  226.             finalPrize=winnerCheckerPrize+bonusGamePrize;
  227.         System.out.println("You have won the total of:"+finalPrize+"€");
  228.         }
  229. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top