Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment 10: Arrays Description In the card game in-between two cards are deal

ID: 3535579 • Letter: A

Question

Assignment 10: Arrays


Description

In the card game in-between two cards are dealt face up on the table and players bet whether the value of the next card will be between them or not. You will write a program for a simplified version of in-between.
Functional requirements:

1. The program will prompt the user for the number of cards in the deck. In this version of in-between the deck consists of N cards, each labeled with a distinct integer from 1 to N. For smooth solo game play, the size of the deck must be a multiple of 3. Reprompt if the user enters a value that is NOT a positive integer divisible by 3. (Use the % operator for this.)

2. Create a deck of N cards, implemented an array of integers.

3. Shuffle the deck. This entails randomly selecting 2 positions in the deck, swapping the cards (ints) located at those positions, and repeating this process N times.

4. Deal 2 cards from the deck, displaying their values to the player and updating the effective size of the deck.

5. Display the player's account balance and prompt the player to bet. The player begins the game with 10 points. Each round he must bet exactly 1 point, either on between (b), or outside (o). If the player enters a value other than b or o, the program reprompts.

6. Deal a card from the deck. If the player was correct his score goes up 1, if not it goes down 1.

7. If the player has 0 points, the game is over. Otherwise, prompt the player to see if he wants to continue. If no, the game is over. If yes, continue.

8. If the deck is empty, back to step 2. Otherwise, go back to step 4.

Non-Functional requirements:

You program must implement and use the following methods:

public static void initDeck(int[] deck)

//takes an array and initializes its values to 1, 2, …

public static void swap(int[] deck, int p1, int p2)

//swaps the values in deck at positions p1 and p2

public static void shuffle(int[] deck, int swaps)

//repeat swaps times: generate 2 random positions in deck and swap



Explanation / Answer

import java.util.Random;import java.util.Scanner; public class InBetween { public static void main(String[] args) { int balance = 10; Scanner in = new Scanner(System.in); boolean cont = true; while(cont) { int deck[]; System.out.print("Enter the number of cards in the deck: "); int length = in.nextInt(); while(length % 3 != 0)