/********************* Game of War ************************** A stub version illustrating how to set up the classes, construct instances and invoke methods, from the design. Programmer: Glenn D. Blank ************************************************************/ import java.util.*; //for LinkedList or ArrayList /** Represents a playing card */ class Card { public Card(int n) { //Stub constructor, just display its argument for now System.out.println("Card constructor with argument "+n); } //Card has other methods, too: see design } /** Represents a pile of cards as a queue */ class Pile { private LinkedList pile; //instance variable holds data //Use JDK class LinkedList or ArrayList to implement pile Pile() { pile = new LinkedList(); } //Construct the list Card nextCard() { Card card = (Card) pile.getFirst(); //get card from top of pile pile.removeFirst(); //remove it from pile return card; } void putCard(Card card) //adds card to bottom of pile { } //Stub: see design for details boolean noMoreCards() //true if no more cards in pile { return true; } //Stub: see design for details int size() { return 0; } //see design for details } /** Represents a deck of playing cards */ class Deck { /** construct array of 52 Cards */ final static int MAXCARDS=52; //Number of cards in a deck public static Card deck[] = new Card[MAXCARDS]; //Construct one deck Deck() { //for each n, 1 to 52, construct Card(n) and insert in deck[n] System.out.println("Construct Deck..."); //shuffle deck } /** arrange cards into two Piles */ void deal(Pile p1,Pile p2) { //for each card in deck, put every other card in one of two piles System.out.println("Deal cards into pile..."); } } public class WarStub //Note: one public class per file (other classes are implicitly private { // execute application static Pile war; //a "war" pile to collect cards until someone winds a round //Note: Because main() is static, variable war must also be static public static void main( String args[] ) { Deck d = new Deck(); //Create and shuffle a deck //Construct piles for player1 and player2 Pile player1 = new Pile(); Pile player2 = new Pile(); d.deal(player1,player2); //deal cards from deck into two piles play(player1,player2); //Start play: see design for details } /** Play a round of war */ static boolean play(Pile player1,Pile player2) { //Note: because main() is static, play() must be static System.out.println("Start play..."); return true; //boolean method must return a boolean value } //play() }