// CS7 - Keno project (covering arrays) // // This program plays a game of keno with the user. The user specifies // how much s/he wants to wager, selects 7 integers between 1 and 80, and // then finds out the results based on keno scoring. // // It is difficult to win much with this version (naturally!), so to // increase your chances, just decrease BOARD_MAX (making the range 1 // through the new value, like 1-60 or something). You can also increase // NUM_UPICKS, but if you match more than 7 it will not recognize that. import tio.*; class keno { static final int BOARD_MAX = 80; static final int NUM_UPICKS = 7; static final int GAME_PICKS = 20; public static void main (String[] args) { // userPicks holds 7 integers between 1 and 80. int [] userPicks = new int[NUM_UPICKS]; // board is an array of booleans and we use slots 1-80. 20 of these // will be set to true indicating which numbers were picked. boolean [] board = new boolean[BOARD_MAX+1]; int wager, winnings, matches; System.out.println("Welcome to Keno!"); System.out.print("How much would you like to wager? (Whole # only): "); wager = Console.in.readInt(); // get the picks from the user then load the random picks on the board loadPicks(userPicks); printPicks(userPicks); // print the picks back for the user loadBoard(board); printBoard(board); // print the board System.out.println(); // calculate how many matches there are between the user & board matches = countMatches(userPicks, board); System.out.println("You had " + matches + " matches with the board."); // finally, print the winnings, if any. winnings = getWinnings(wager, matches); if (winnings==0) System.out.println("Sorry, you did not win any money."); else System.out.println("You get back $" + winnings); } // loads the user's picks into a, does not permit duplicates static void loadPicks(int [] a) { int candidate=0; for (int i=0; i high) { System.out.print("Please enter an integer between " + low + " and " + high + ": "); n = Console.in.readInt(); } return n; } // prints the values in the user's array static void printPicks(int a []) { System.out.print("Your picks: "); for (int i=0; i