Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fill in the code to run the program: import java.util.Scanner; import java.util.Random; public class A1Q4{ /** * Array used to store the full deck of

image text in transcribedFill in the code to run the program:

import java.util.Scanner; import java.util.Random; public class A1Q4{ /** * Array used to store the full deck of cards, */ private static String[] deck; /** * The current number of cards in the full deck of cards */ private static int sizeDeck; /** * Array used to store the player's deck of cards */ private static String[] playerDeck; /** * The current number of cards in the player's deck of cards */ private static int sizePlayerDeck; /** * Array used to store the computer's deck of cards */ private static String[] computerDeck; /** * The current number of cards in the computer's deck of cards */ private static int sizeComputerDeck; /** * An instance of java.util.Scanner, which will get input from the * standard input */ private static Scanner sc; /** * An instance of java.util.Random, to generate random numbers */ private static Random generator; /** * Constructor of the class. Creates the full deck of cards */ public A1Q4(){ sc = new Scanner(System.in); generator = new Random(); String[] suits = {"\u2660", "\u2661", "\u2662", "\u2663"}; String[] ranks = {"2","3","4","5","6","7","8","9","10","J","Q","K","A"}; sizeDeck = suits.length*ranks.length - 1; deck = new String[sizeDeck]; int index = 0; for(int i =0 ; i  

// new class

public class ArrayStringsTools{ /** * Prints the strings contained in arrayOfStrings * * @param arrayOfStrings the array of Strings * @param currentSize the number of strings in the arrayOfStrings, * stored from arrayOfStrings[0] to arrayOfStrings[currentSize-1] */ public static void printArray(String[] arrayOfStrings, int currentSize){ if( arrayOfStrings == null || currentSize > arrayOfStrings.length) { System.out.println("ArrayStringsTools.printArray: wrong call"); return ; } for(int i = 0; i  arrayOfStrings.length) { System.out.println("ArrayStringsTools.sortArray: wrong call"); return ; } java.util.Arrays.sort(arrayOfStrings, 0, currentSize ); } /** * Randomly shuffles arrayOfStrings. * * @param arrayOfStrings the array of Strings * @param currentSize the number of strings in the arrayOfStrings, * stored from arrayOfStrings[0] to arrayOfStrings[currentSize-1] */ public static void shuffleArray(String[] arrayOfStrings, int currentSize){ if( arrayOfStrings == null || currentSize > arrayOfStrings.length) { System.out.println("ArrayStringsTools.shuffleArray: wrong call"); return ; } java.util.Random generator = new java.util.Random(); for(int i = currentSize-1 ; i > 1 ; i--){ swapItems(arrayOfStrings, i,generator.nextInt(i-1)); } } private static void swapItems(String[] arrayOfStrings, int i, int j){ String intermediate = arrayOfStrings[i]; arrayOfStrings[i]=arrayOfStrings[j]; arrayOfStrings[j]=intermediate; } /** * Removes the string at arrayOfStrings[itemToRemove] and * * @param arrayOfStrings the array of Strings * @param currentSize the number of strings in the arrayOfStrings, * stored from arrayOfStrings[0] to arrayOfStrings[currentSize-1] * @param itemToRemove index of the item to remove from arrayOfStrings * @return the new size of the modified arrayOfStrings */ public static int removeItemByIndex(String[] arrayOfStrings, int currentSize, int itemToRemove){ if( arrayOfStrings == null || currentSize > arrayOfStrings.length) { System.out.println("ArrayStringsTools.removeItemByIndex: wrong call"); return currentSize; } if( itemToRemove = currentSize ) { System.out.println("ArrayStringsTools.removeItem: item " + itemToRemove + " out of bounds. Array Unchanged."); return currentSize; } int i; for( i = itemToRemove; i  arrayOfStrings.length) { System.out.println("ArrayStringsTools.appendItem: wrong call"); return currentSize; } if( currentSize == arrayOfStrings.length) { System.out.println("ArrayStringsTools.appendItem: array full. Array Unchanged."); return currentSize; } arrayOfStrings[currentSize++]=itemToAdd; return currentSize; } } 

the "Old Maid" card game In order to do our impler entation of the card gaue, we need to use a Java valent for Python's lists. We are going to use array As you know, one limitation with Java arrays is that they are offixed size. We will soon see alternatives that can be used when the number of elements to store is not known in advance, but for this game, it hrns ont that the maximum number of cards in any deck is known: there are only 51 cards in this game. so we can use arrays of size 51. aud we are sure that they will always be large enough to hold as mauy cards as we could possibly have in any one deck. Having an array large enough eusures that we will be able to add and remove from that array without having to worry about overflows. However, there is direct way to know how mauy elements are in the array currently. order to address this problem we will have to maintain an additional cointer for each nt our arrays. These counters record the enrrent her ot elements in the array (from 0 to 5 thus). To facilitate our tasks, a utility class is provided. ArrayStrings lools. It can do a few basic things on our arrays such as sorting them. shuffling them etc. A detailed description of the classes can be found here Al 24-java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is meant by decentralisation of authority ?

Answered: 1 week ago

Question

Briefly explain the qualities of an able supervisor

Answered: 1 week ago

Question

Define policy making?

Answered: 1 week ago

Question

Define co-ordination?

Answered: 1 week ago

Question

What are the role of supervisors ?

Answered: 1 week ago