Omar_Natour

Natour, O. 11/30/15 Csc-111-D01 HW#16

Nov 30th, 2015
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. /*
  2.  * Name:Omar Natour
  3.  * Date: 11/30/2015
  4.  * Course Number: Csc-111-D01
  5.  * Course Name: Intro To Java
  6.  * Problem Number: HW# 16
  7.  * Short Description of the Problem: Write a short program to find 5 + 1 random numbers for a lottery drawing.
  8.  */
  9.  
  10. import java.util.Arrays;
  11. import java.util.Scanner;
  12. import java.lang.Math;
  13.  
  14. public class LuckForLife {
  15.     public static void main(String args[]) {
  16.         final String TITLE = "Lucky For Life Lottery Nubmers Generator";
  17.         final String CONTINUE_PROMPT = "Do this again? [y/N] ";
  18.  
  19.         System.out.println("Welcome to " + TITLE);
  20.         Scanner sc = new Scanner(System.in);
  21.         String doover;
  22.         do {
  23.             output();
  24.             System.out.print(CONTINUE_PROMPT);
  25.             doover = sc.nextLine();
  26.         } while (doover.equalsIgnoreCase("Y"));
  27.         sc.close();
  28.         System.out.println("Thank you for using " + TITLE);
  29.     }
  30.  
  31.     public static void output() {
  32.         int[] x1 = GenNum();
  33.         int luckB = (int) (Math.random() * 44 + 1);
  34.  
  35.         Arrays.sort(x1);
  36.  
  37.         System.out.print("Your Lucky For Life Cash numbers are:");
  38.         for (int i = 0; i < 5; i++)
  39.             System.out.printf("%3d", x1[i]);
  40.  
  41.         System.out.printf("\n" + "Your Lucky Ball Number is:" + "%3d", luckB);
  42.         System.out.println();
  43.  
  44.     }
  45.  
  46.     public static int[] GenNum() {
  47.         int x[] = new int[5];
  48.         boolean dup = true;
  49.  
  50.         for (int i = 0; i < x.length; i++)
  51.             x[i] = (int) (Math.random() * 44 + 1);
  52.  
  53.         while (dup) {
  54.             if (x[0] == x[1] || x[0] == x[2] || x[0] == x[3] || x[0] == x[4]) {
  55.                 x[0] = (int) (Math.random() * 44 + 1);
  56.                 dup = true;
  57.             } else if (x[1] == x[2] || x[1] == x[3] || x[1] == x[4]) {
  58.                 x[1] = (int) (Math.random() * 44 + 1);
  59.                 dup = true;
  60.             } else if (x[2] == x[3] || x[2] == x[4]) {
  61.                 x[2] = (int) (Math.random() * 44 + 1);
  62.                 dup = true;
  63.             } else if (x[3] == x[4]) {
  64.                 x[3] = (int) (Math.random() * 44 + 1);
  65.                 dup = true;
  66.             } else
  67.                 dup = false;
  68.         }
  69.         return x;
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment