CSE10: Introduction to Computing
Assignment #7 (Objects First with Java, chapter 4: Grouping Objects,
The Universal Computer, chapters C: Strings and Arrays, 6: Algorithms and Analysis, and 7: Operating Systems and Networks)

The labs starting last Thursday focused on Strings and Arrays (OF chapter 4 and UM chapter C); the labs starting this Thursday will feature the multimedia on Operating systems and Networks (UM chapter 7).  You will also work on the design of continue the of the War program. (You need to learn how about Arrays and ArrayList to design the War program.)

Homework exercises (hand in .java source code for any programming exercises):
CSc13 exercises:  OF 4.3, 4.4. 4.23, 4.24, UM C.1, C.4, C.15, 6.6, 6.15, 6.19, 7.3, 7.8, 7.15, 7.28, 7.33, 7.36, 7.38.
CSc14: exercises OF 4.3, 4.4, 4.13, 4.16, 4.23, 4.24, UM C.1, C.4, C.9, C.11, C.12, C.15, C.19, 6.6, 6.7, 6.9, 6.15, 6.19, 7.8, 7.15, 7.23, 7.28, 7.33, 7.36. For exercise C.9, I supply the program reverse.java, which I discussed in class, as a similar example. Exercise 6.9 refers to BinarySearch.java; use H:\ucomp\chapC\BiSearch\BiSearch.java.  Pair programming recommended (though not required) for C.9 and 6.7. For 6.7, you may modify H:\ucomp\chapC\SelectionSort\SelectionSort.java.

Below I supply my version of a use case analysis for the "War" game, plus a partial design.  As part of this assignment, you will complete the design.  Note: both CSE13 and CSE14 students will work on the design part of this project for this assignment.  CSE14 students only will implement it, as part their final homeework assignment (not yet!).  Also, it is strongly recommended that you work on the "War" game design (and later programming) in pairs.  In fact, unless either Faisal  Khan or I excuse you from pair design/programming for some legitimate reason which you must explain to one of us, it is required.  

Extra credit: C.13 (where it refers to the "previous" chapter, look at chapter 7, p.21).  You can some extra credit for designing a psuedocode algorithm for this problem (especially CSE13 students), more for implementing it, more yet for the "extra credit" mentioned in the exercise itself.

Due: Tuesday, 11/19, 1:10PM, hard copy in class, electronic copy in CSE10 Drop Box (so that TA can review programs if necessary).  For pair designs/programs, each partner should mention their partner's name at the top of their work.  If you need extra time to do this assignment, please put late work in Faisal Khan's mailbox in 304 Packard Lab.

Here is my use case analysis for War, followed by my class and methods pseudocode design for two classes.  
Your task (part of this assignment) is to complete the design of classes and methods pseudocode for the game.
Again, it is strongly recommended that you work on the "War" game design (and later programming) in pairs.

Use case: Game of War
  1. Shuffle a deck of 52 cards.
  2. Deal pile of cards to two players, face down.
  3. Both players show top card.
  4. Player with higher card puts both cards at bottom of his/her pile.
  5. Go to step 3.
Alternative: War
  At step 4, both cards have same value.
  6. Declare "war".
  7. Both players draw three cards face down.
  8. Go to step 3.
Alternative: not enough cards for War.
  At step 7, a player does not have three cards.
  9. Draw all available cards except one (for step 3).
  9b. If this player has no cards left, put top card back (for step 3).
  10. Go to step 3.
Alternative:
  At step 5, player has no more cards.
  Other plays wins the game.

Design:
   class Deck    Represents a deck of playing cards
     Deck()        construct array of 52 Cards
     shuffle()     shuffle deck into random order
     deal(Pile,Pile)        arrange cards into two Piles
  class Pile    Arrange a player's cards in a queue
     Pile()        construct an empty queue
     nextCard()    returns card from top of pile
     putCard(Card) adds card to bottom of pile
     noMoreCards() true if no more cards in pile
     size()        number of cards in pile
 
Pseudocode:
     Pile()                           
        construct an empty pile of Cards
     Card nextCard()          
        get Card from top of Pile
        remove it from Pile
        return Card
     void putCard(Card)          
        add Card to bottom of Pile
     boolean noMoreCards()    
        if pile is empty then true else false
     int size()
        return number of items (cards) in Pile

     Deck()       
         for each n, 1 to 52, construct Card(n) and insert in deck[n]
         shuffle deck
     void shuffle()
         display "Shuffling deck"
         for each card in deck, pick another random card and swap these cards
     void deal(Pile pile1, Pile pile2)
         display "Dealing deck into two piles"
         for each card in deck, put every other card in one of two piles

Prof. Blank