I have the following War Game. How do I update it so that the java program uses an Array List for n player and m decks.
I have already written out the following methods:
Array List for CardPile which contains the makeFullDeck which takes as input int n. This makeFullDeck method should create a full deck which has n copies of every card and then shuffles it.
The new War game using Array List should return an int representing which player won the game.
The below program is my original War game(shown below) i wrote. How do i update this so that the program uses an ArrayList. The update can be in a class class MultiPlayerWar
import java.util.Scanner;
public class War
{
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
String[] names = new String[2];
System.out.println("What is player one's name?");
names[0] = reader.nextLine();
System.out.println("What is player two's name?");
names[1] = reader.nextLine();
int winner = playGame();
System.out.println("The winner was player " + (1 + winner) + ". Congratulations to " + names[winner] + " on his/her hard earned victory!");
}
//returns 0 if first player wins
//returns 1 if second player wins
public static int playGame()
{
CardPile deck = CardPile.makeFullDeck();
CardPile p1 = new CardPile();
CardPile p2 = new CardPile();
while (!deck.isEmpty())
{
p1.addToBottom(deck.removeTopCard());
p2.addToBottom(deck.removeTopCard());
}