Here are some questions students have asked about the final assignment and my replies:

Question:
Could you rephrase the question 8.17?  I don't quite understand what it's asking.
Answer:
Originally, to be copyrightable, material had to be readable by humans.  That's changed.  
But let's suppose the restriction were still in force.  Would source code be copyrightable?  
Would machine code be copyrightable?  What's odd about this situation?  (Hint: Would anyone
need to copy source sode?)

Question:
hello prof blank. w/ the problems 8.25-8.27, what do u want for an answer
exactly? do u just want us to say if its competence, context, or concern?
Answer:
See the five questions at the top of the page (28).

Question:
In exercise 5.7 I don't know what you mean by the question "why were programs designed that would have this flaw in the first place?" Could you please explain?
Answer:
I think you are looking at the wrong exercise.  The 5.7 mentioned in the assignment refers to the one in the Objects First With Java book. 
We did chapter 5 of The Universal Computer several weeks ago.

Question:
I just have a question about Java. Are all objects defaulted passed by reference?
If i send an object to a method that is not defined in its own class definition and alter it, will it be changed in the main method?
Answer:
Yes, all objects are passed by reference.  Primitive types (e.g., int, char, double) are not.
So if you alter the value of an object within a method, the change is a side effect outside
the method.  These methods are called mutators.
gdb
Question:
I simply can't figure out what's wrong with the size() method and the show() method that's causing these errors.
Answer:
I used the BlueJ debugger and determined first of all that your game loop keeps comparing
2 of clubs.  That suggested that you might only have 2 of clus in your deck.  I confirmed that
by adding a show() statement to your Card constructor.  Then I looked closer at your
constructor and saw the bug:

     public Card(int n)  //construct a Card, given n from 1 to 52
        {
         int face = n % 13; //  12 is 12, an Ace; 13 is 1, a Deuce
         int suit = n / 13; //e.g., 12 is 0, a Club; 13 is 1, a Diamond
         System.out.println("Card constructor " + n); show();

The bug: you declare face and suit as LOCAL variables.  Thus the constructor has no
affect on the instance variables of the Card.  Remove the int before face and suit and
your constructor will change instance variables rather than local variables, and you'll
get cards besides 2 of clubs.

Question:
Ok I know what's wrong.  It's the noMoreCards method. I looked at your pseudocode and wrote it out.  It doesn't seem to work correctly. Hopefully you can help me with this....
Answer.
Found your bug.  First, as I'm sure you did, I used the BlueJ debugger to step through your
program.  I saw, as you did, that it played just one round, then stopped.  I looked at the
noMoreCards methods, and didn't see anything wrong with that.
Then, I went one more step in my reasoning: if the game only played one round, then maybe
you dealt only one card in each pile at the outset.
So I looked at your deal method and close inspection revealed the bug:
    public void deal(Pile pile1, Pile pile2)
    {
        System.out.println("Dealing deck into two piles");
        while (n < 52);    // <==
        {
            n = 0;
            //resets the index...

Look carefully at the line with the arrow  before going on with my explanation.  See the bug?

...

In case, you don't....
...
The semi-colon makes an empty statement.  It does nothing 52 times, then performs the
following block just once, hence one card in each pile.

gdb
Question:
After doing a half hours research on the internet, I have come to the conclusion that a "Cannot Resolve Symbol" error is one that is commonly confusing programmers....
There is also a "Incompatible Types" error....
Answer:
You get the error message "incompitable types" for this line:
       {    Card card = pile.get(0);
because pile (an ArrayList) returns an Object, not a Card.  You need to cast Object as an Card:
        {    Card card = (Card) pile.get(0);

You get the error message "cannot resolve symbol" for this line:
         card1 = player1.Pile.nextCard( );
because Pile is not a public member of player1 (it's the return type of nextCard().  You just
invoke the member, not its type, e.g.:
                 card1 = player1.nextCard( );

You get the error message "cannot resolve symbol" for this line:
                      {    if (player1.size( ) > 1)
because size() has not been declared as a member of Pile, of which player1 is an instance.
Why not use methods noMoreCards(), which has been declared?  

Question:
we have attached our two class files, we are making progress, but we get a
strange error message when we run our deck method. please see the output
below (also could you tell use why we are getting the strange text beside
our card names):
2 of Clubs Card@ea2dfe
3 of Clubs Card@7182c1
[all the cards...] Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException ...
Answer:
1) The strange text besides your card names is caused by this statement:
   System.out.println(carddeck[n]);
It prints out a Java representation of a Card plus its reference in memory.
It appears after you construct each Card (and the constructor runs show()).
2) You get the out of bounds message because, well, your loop goes out bounds
(an "off by one" error).  Look carefully at these two lines:
        carddeck = new Card[51];
        for (int n = 0; n <= 51; n++)
What's the upper bounds index of your array?  (Think about the lower bounds index.)  

Question:
Our war program compiles. However, it does not run. When we run the program, a DOS box pops up and disappears immediately. Using PrintScreen to attempt see what the box says before it disappears, we figured out that there is an error message to the effect of Exception in Main
Answer:
I took a look at your program and noticed something right away: your program does not
have a main. Where is it supposed to start? It also doesn't have any public classes.
It must have one (and only one) public class and main goes in this class.
BTW, since main must be static, any methods it class must either be static or construct
instances (which may in turn call any methods). Any variables in main must either be static
or local to main.

Question:
There's a logic error in it and it doesn't seem to loop correctly.
Answer:
May I suggest you put more System.out.println statements in the program to see how far it gets?
Or use the debugger in BlueJ to step through your program.

Question:
I've been having some trouble with the war game.  I can't get the classes to compile and I don't want to implement the game before the classes compile.  So here are the errors I'm getting:

.\Pile.java:25: <identifier> expected
   public void putCard(Card)
                           ^ You need a formal parameter name, e.g.:
    public void putCard(Card card)
Card is the type, card is the formal parameter name, to which you refer within the method.

.\Pile.java:40: ')' expected
    }
        ^ I looked up at the previous lines and saw the missing parentheses here:
    if (pile.size == 0)
Unlike an array.length, size is a method; hence it requires parentheses, e.g., pile.size().

C:\Documents and Settings\Joe\Desktop\Joe's Folder\Lehigh\War\Deck.java:26: cannot resolve symbol
symbol  : method Card  (int)
location: class Deck
            Card(n);
                       ^ This is a bit more complicated to explain.  You do have a method with this signature in Card.java:
      public void Card(int n)
But you aren't calling it as a method but as a constructor.  If it were a method, you would have
to use dot notation to call it, on an instance, e.g.:, assuming card were an instance of Card:
     c.Card(n);
But this is obviously not what you intended.  You intended Card(n) to be a constructor.
You need to change the signature of Card(n) to be a constructor:
      public Card(int n)
However, you will STILL get the unsolved symbol error until you do one more thing.  Change:
     class Card    //Represents a playing card
to: public class Card    //Represents a playing card
Remember, you should have one public class per file, and that file must be public in order
for other classes to refer to public methods or constructors within that class.
Alternatively, you could put all your classes in ONE file.  Then just one class would need
to be public (and have the main method).  Then that class would automatically have access
to all the other classes in the same file.  But if you put each of your classes in a separate file
(as Java programmers commonly do), then the class must be declared public.
Finally, there is yet another problem with the way you are CALLING your constructor.
Instead of:
    Card(n);
it should be:
    Card card = new Card(n);
My version declares variable card of type Card, then constructs an instance.  Got it?

C:\Documents and Settings\Joe\Desktop\Joe's Folder\Lehigh\War\Deck.java:28: cannot resolve symbol
symbol  : variable Card
location: class Deck
            deck.add(Card);
                                ^ This is similar to a problem noted above: you are confusing type and instance.  Suppose
you follow my recommendation above and construct an instance of type Card, card.
Then you would could pass this instance to the add method:
    deck.add(card);
.\Pile.java:17: cannot resolve symbol
symbol  : variable pile
location: class Pile
        pile = new LinkedList();
               ^ You haven't declared variable pile.

.\Pile.java:22: cannot resolve symbol
symbol  : variable pile
location: class Pile
        show(pile.getFirst());
                    ^ Ditto.

.\Pile.java:25: missing method body, or declare abstract
   public void putCard(Card)
               ^ See note above about this method.  (You need to declare a formal parameter name.)
gdb

A bit later, the same student got back to me:
I'm still having some problems with the base classes.  Just two really and here they are:

C:\Documents and Settings\Joe\Desktop\Joe's Folder\Lehigh\War\Deck.java:30: cannot resolve symbol
symbol  : constructor Card  (int)
location: class Card
            card = new Card(n);
                              ^ In Card.java, you still have this signature:
    public void Card(int n)
Get rid of the "void". With "void" it's a method; a constructor does not have a return type.

C:\Documents and Settings\Joe\Desktop\Joe's Folder\Lehigh\War\Deck.java:32: cannot resolve symbol
symbol  : method add  (Card)
location: class Card[]
            deck.add(card); Arrays don't have an "add" method; ArrayLists do.  Instead use the subscript operator, [].
gdb

Another pair of students asked:
You are trying to shove a Card into an int container.  E.g.: you declared deck as an array of int:

    int [] deck;
    deck = new int[51];  ....
    deck[n] = new Card(n);

Then you attempt to assign an instance of Card as an element of deck. Instead, you should
declare deck as an array of Card.
gdb

A pair of students sent me their code and here are my comments:
import Card;
You don't need to import from a class in the same folder.
...
      Card Deck [] =  new Card [52]; //creates an array for the 52 cards
Avoid magic numbers!
...
 Card newCard = new Card(i+1);
The reason the compiler complains about this line is that you declared in Card.java:
   public void Card(int n)
This creates a method with return type void.  A constructor has no return type.  It should be:
   public Card(int n)
...
       { int n = Random.nextInt(52);
You are confusing classes and instances.  It's instance . method, not class . method. E.g.:  
	{ int n = randomGenerator.nextInt(52);
....
      {pile1[i] = Deck[i];
If  pile is defined as an ArrayList or a LinkedList, you can't use [] notation to access elements.
See my design notes.

C:\War\WarGame.java:41: incompatible types
found   : int
required: boolean
        if (winner = 1)
                   ^ The operator = means assignment.  You meant ==, e.g.:
    if (winner == 1)

C:\War\WarGame.java:43: 'void' type not allowed here
            while (WarPile.size() > 0)
                                          ^
Probably your size method has a void return type; shouldn't it be int?

C:\War\WarGame.java:153: non-static method game() cannot be referenced from a static context
        game();
               ^ Method
Method main is static and method game is not static.  You should either construct the game,
then call its game method, OR make the game method (and any methods it calls) static.
gdb

Questions about replace.cpp:
The problem is in this line:
  string modified(string original);
You are confusing the compiler by sending what looks like two parameters.  Try this:
  string modified(original);

#include <string.h>
Should be #include <string>
...
void replace ( )
The signature should have a return type (the new string) and several arguments (original string
and a couple of characters).
	char replace = "a";	//Arbitrary character to insert into
Can't assign a string to a char.


Questions about replace.cpp:
The problem is in this line:
  string modified(string original);
You are confusing the compiler by sending what looks like two parameters.  Try this:
  string modified(original);

#include <string.h>
Should be #include <string>
...
void replace ( )
The signature should have a return type (the new string) and several arguments (original string
and a couple of characters).
	char replace = "a";	//Arbitrary character to insert into
Can't assign a string to a char.

Question:
Where can the powers.java program be located? I found it the other day but i can't seem to find it for some reason...i forgot which folder it was in.
Answer:
H:\ucomp\chapb\multimedia