/*
Name of program: Keno Game without GUI
Programmer's name: ABC
Current Date: dd/mm/yyyy
Computer system and compiler you are using: Win 8, JDK 1.7
Brief description of the program (1-5 sentences): Play Keno game
Variable names (if any) and descriptions of what they represent:
*/
import java.util.Scanner;
public class HW6_KenoGameDriver
{
static Scanner oScanner = new Scanner(System.in);
public static void main(String[] args)
{
HW6_KenoGame oKenoGame = new HW6_KenoGame();
boolean b_IsGameContinue = true;
// determine if user want to repeat
while(b_IsGameContinue)
{
oKenoGame.drawNumbers();
getKenoGameUserChoices(oKenoGame);
oKenoGame.getResults();
oKenoGame.displayResults();
b_IsGameContinue = isGameContinue();
// Ask if user wants to repeat
//oKenoGame.drawNumbers();
}
}
public static void getKenoGameUserChoices(HW6_KenoGame oKenoGame)
{
int i_NumOfSpotToChose = 0;
int i_amountOfBet = 0;
while (i_NumOfSpotToChose < 1 || i_NumOfSpotToChose >= HW6_KenoGame.PAYOFF.length)
{
System.out.print("How many spots do you want to choose? (max. " + HW6_KenoGame.DRAWN_NUMBERS + "): ");
i_NumOfSpotToChose = oScanner.nextInt();
// if (i_NumOfSpotToChose < 1 || i_NumOfSpotToChose >= HW6_KenoGame.PAYOFF.length)
// display error message
}
while(i_amountOfBet <= 0)
{
System.out.print("What is your bet (at least $1): ");
i_amountOfBet = oScanner.nextInt();
}
oKenoGame.createKenoPlayer(i_NumOfSpotToChose, i_amountOfBet);
int i_Counter = 0;
while (i_Counter < i_NumOfSpotToChose)
{
System.out.print(String.format("Enter number (1-%d) #%d: ", HW6_KenoGame.MAX_KENO_NUMBER, (i_Counter+1)));
switch(oKenoGame.setUserDrawnSpot(oScanner.nextInt()))
{
case -1:
System.out.println(String.format("Number is out of range (1-%d)", HW6_KenoGame.MAX_KENO_NUMBER));
break;
case 1:
System.out.println("You already chose that number!");
break;
case 0:
i_Counter++;
break;
default:
break;
}
}
}
// Ask if user wants to repeat --> Copied this method from HW2
public static boolean isGameContinue()
{
boolean isGameContinue;
System.out.print("Play another game? (y for yes): ");
String s_UserInput = oScanner.next();
if(s_UserInput != null && ! s_UserInput.isEmpty())
{
System.out.println(s_UserInput.substring(0, 0).toUpperCase());
isGameContinue = (s_UserInput.toUpperCase().charAt(0) == 'Y')? true : false;
}
else
isGameContinue = false;
return isGameContinue;
}
}
/*
Output:
How many spots do you want to choose? (max. 15): 4
What is your bet (at least $1): 10
Enter number (1-80) #1: 20
Enter number (1-80) #2: 30
Enter number (1-80) #3: 40
Enter number (1-80) #4: 10
76 15 69 21 43 27 8 62 65 4 50 5 68 44 57 17 54 2 31 52
Player's spots: 20 30 40 10
Player matched 0 spot(s), bet $10 and won $0.00
Play another game? (y for yes): yeah
How many spots do you want to choose? (max. 15): 2
What is your bet (at least $1): 100
Enter number (1-80) #1: 100
Number is out of range (1-80)
Enter number (1-80) #1: 0
Number is out of range (1-80)
Enter number (1-80) #1: -1
Number is out of range (1-80)
Enter number (1-80) #1: 33
Enter number (1-80) #2: 200
Number is out of range (1-80)
Enter number (1-80) #2: 33
You already chose that number!
Enter number (1-80) #2: 300
Number is out of range (1-80)
Enter number (1-80) #2: 33
You already chose that number!
Enter number (1-80) #2: 44
16 57 19 40 80 26 42 20 6 35 70 76 68 27 8 18 1 7 3 17
Player's spots: 33 44
Player matched 0 spot(s), bet $100 and won $0.00
Play another game? (y for yes): yes
How many spots do you want to choose? (max. 15): 20
How many spots do you want to choose? (max. 15): 2
What is your bet (at least $1): -5
What is your bet (at least $1): 50
Enter number (1-80) #1: 10
Enter number (1-80) #2: 20
16 17 65 23 57 52 38 30 48 73 47 44 27 53 35 76 22 8 63 66
Player's spots: 10 20
Player matched 0 spot(s), bet $50 and won $0.00
Play another game? (y for yes): YYYYY
How many spots do you want to choose? (max. 15): 5
What is your bet (at least $1): 80
Enter number (1-80) #1: 1
Enter number (1-80) #2: 70
Enter number (1-80) #3: 10
Enter number (1-80) #4: 1
You already chose that number!
Enter number (1-80) #4: 10
You already chose that number!
Enter number (1-80) #4: 60
Enter number (1-80) #5: 80
19 18 17 54 33 49 38 31 67 78 29 11 75 22 46 79 37 69 12 23
Player's spots: 1 70 10 60 80
Player matched 0 spot(s), bet $80 and won $0.00
Play another game? (y for yes): yes
How many spots do you want to choose? (max. 15): 4
What is your bet (at least $1): 22
Enter number (1-80) #1: 44
Enter number (1-80) #2: 66
Enter number (1-80) #3: 77
Enter number (1-80) #4: 22
53 60 25 5 7 32 75 68 73 65 42 2 58 15 36 14 35 20 13 6
Player's spots: 44 66 77 22
Player matched 0 spot(s), bet $22 and won $0.00
Play another game? (y for yes): yes
How many spots do you want to choose? (max. 15): 8
What is your bet (at least $1): 15
Enter number (1-80) #1: 10
Enter number (1-80) #2: 20
Enter number (1-80) #3: 30
Enter number (1-80) #4: 40
Enter number (1-80) #5: 50
Enter number (1-80) #6: 60
Enter number (1-80) #7: 70
Enter number (1-80) #8: 80
15 19 7 26 49 58 6 5 48 68 28 12 16 73 47 36 23 17 50 22
Player's spots: 10 20 30 40 50 60 70 80
Player matched 1 spot(s), bet $15 and won $0.00
Play another game? (y for yes): no
*/