import java.util.Scanner;
import java.util.Arrays;
/*
Courtney Fox
Professor Yao
CIS 201 - FoxPJ3
10/4/17
Purpose of program: Create a java program that let's the user
play a powerball game.
Program Logic:
*/
public class FoxPJ3
{
public static void main(String[] args)
{
//Variables
int[] whiteB = new int[5]; //68 white balls, draw 5 between (1-68)
int redB; //26 red balls, draw 1 between (1-26)
int[] powerW = new int[5]; //White Powerball Numbers
int powerR; //Red Powerball Numbers
int jackP; //All 6 balls match (Jackpot)
int secondP;//All 5 white balls match (1 million cash)
int thirdP; //4 white balls match and the red ball (50,000 cash)
//Scanner
Scanner input = new Scanner(System.in);
//User Input
for(int i = 0; i < whiteB.length; i++)
{
do
{
System.out.println("Please a number between 1 and 68 (#" + (i + 1) + "): ");
whiteB[i] = input.nextInt();
} while (whiteB[i] <= 0 || whiteB[i] > 68);
}
do
{
System.out.println("Please pick the powerball number between 1 and 26: ");
redB = input.nextInt();
} while (redB <= 0 && redB > 26);
//Display users numbers
System.out.print("Your numbers are: ");
System.out.print(Arrays.toString(whiteB));
System.out.print(" and "+redB);
//Winning Numbers
for (int index = 0; index < powerW.length; index++)
{
powerW = (int) (Math.random() * 68) + 1;
}
System.out.println("The Winning Numbers are: " +powerW);
powerR = (int) (Math.random() * 26) + 1;
System.out.print(" and "+ powerR);
}
}
Intructions: Please a Java program that allows the user to play the Powerball lottery game. • 68 white balls o Draw 5 white balls (between 1 and 68) • 26 red balls o Draw 1 red ball – the Powerball (between 1 and 26) Winning: • Jackpot – matching all 5 white balls and the red ball • Second prize ($1 million in cash) – matching all 5 white balls • Third prize ($50,000 in cash) – matching 4 white balls and the Powerball This program: • creates 5 random numbers between 1 and 68 as the winning white balls • creates 1 random number between 1 and 26 as the winning Powerball number • prompts the user/player to enter 5 numbers, between 1 and 68, as white ball numbers • prompts the user/player to enter 1 Powerball number, between 1 and 26 • determines if the user/player wins the jackpot, second prize, third prize, or nothing
Aucun commentaire:
Enregistrer un commentaire