Advertisement
Omar_Natour

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

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