Advertisement
Guest User

lottery-ibat

a guest
Nov 11th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package javaapplication9;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.Random;
  10. import java.util.Scanner;
  11.  
  12. /**
  13.  *
  14.  * @author jrowley
  15.  */
  16. public class JavaApplication9 {
  17.  
  18.     /**
  19.      * @param args the command line arguments
  20.      */
  21.     public static void main(String[] args) {
  22.         // TODO code application logic here
  23.         Scanner input = new Scanner(System.in);
  24.         //  System.out.print("Enter your name:\t");
  25.         // String yourName = input.nextLine();
  26.         int costOfPanel = 2;
  27.         int lottoPanels = 1;
  28.         do {
  29.             System.out.printf("Hi Pick number of Panels (1-6)\t");
  30.             lottoPanels = input.nextInt();
  31.         } while (lottoPanels > 6 || lottoPanels < 1);
  32.        
  33.         int numberOfQuickPicks = 0;
  34.        
  35.          do {
  36.             System.out.printf("Hi number of quickPicks (1-%d)\t", lottoPanels);
  37.             numberOfQuickPicks = input.nextInt();
  38.         } while (numberOfQuickPicks > lottoPanels || numberOfQuickPicks < 0 );
  39.  
  40.         for (int i = 0; i < numberOfQuickPicks; i++) {
  41.  
  42.           generateLotteryPanelQP();
  43.  
  44.         }
  45.        
  46.          for (int i = 0; i < lottoPanels-numberOfQuickPicks; i++) {
  47.  
  48.               System.out.println("manual entry required");
  49.         }
  50.        
  51.         int totalCost = costOfPanel* lottoPanels;
  52.        
  53.          System.out.printf("Price of Lottery is %d\t", totalCost);
  54.     }
  55.  
  56.     public static void generateLotteryPanelQP() {
  57.  
  58.         ArrayList<Integer> listOfNumbers = new ArrayList<>();
  59.         // create instance of Random class
  60.         Random rand = new Random();
  61.  
  62.         for (int i = 0; i < 6; i++) {
  63.             int randomNumber = rand.nextInt(50);
  64.  
  65.             while (listOfNumbers.contains(randomNumber)) {
  66.  
  67.                 randomNumber = rand.nextInt(50);
  68.             }
  69.             // listOfNumbers.set(i,randomNumber);
  70.             listOfNumbers.add(randomNumber);
  71.         }
  72.         System.out.print("You got: ");
  73.  
  74.         for (Integer i : listOfNumbers) {
  75.  
  76.             System.out.printf("%d\t", i);
  77.         }
  78.         System.out.print("\n");
  79.     }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement