Suggestions and Hints for Project #1 Last modified: 9/20/2002. 0. Be sure to look at the posted project updates. 1. Take a look at the definition of the standard Java StringBuffer class. You may find it useful for implementing toString methods. 2. You may find ArrayList (or Vector) and LinkedList in java.util useful. 3. When copying arrays, ArrayLists, LinkedLists, etc., whose items have reference types, always remember that you are ONLY COPYING POINTERS! If you copy an array of Polynomials, for example, and then change a field in one of the Polynomials in the original array, that field also changes in the corresponding item of the copy. So, if you DO introduce methods that change a Polynomial's fields (or a Term or Factor, if you introduce such types), always be aware of what other Polynomials (that you intended to be separate) might get affected by any change you make. 4. Handling expressions like 'x-3y' is a little tricky. A StreamTokenizer will return 'x', the number -3, and 'y'. According to the handout, you are supposed to treat this as x+(-3y), not as -3xy. It's not too difficult---just remember that a negative number marks the end of one term and the start of another, whereas a non-negative number does not. 5. The field inp.ttype is of type int. However, when you read an "ordinary" character (punctuation, lower-case letters), it is supposed to represent a character (its value will be the numeric ASCII code used for that character: for example 'a' will show up as 97). Just remember that you may need to tell Java (or GJDB) to treat inp.ttype as a character for some purposes, using a cast. For example, in GJDB, you might write print (char) inp.ttype Be especially careful in printing or in adding to a string. For example, if I've just read an 'x', then the String "I just read " + inp.ttype is "I just read 97". You probably meant "I just read " + (char) inp.ttype, which prints "I just read x". 6. The type char is one of the numeric types (see PIJ 6.3). All characters in Java are represented by numbers according to a standard known as Unicode. Conveniently, the letters 'a'-'z' are represented by consecutive numbers, as are 'A'-'Z' and '0'-'9'. That means that expressions such as x - 'a' will convert a letter a-z stored in int or char variable x into a number in the range 0-25 . The reverse translation (which you won't need in this projectx) is (char) (n + 'a'). 7. In GJDB, when you do a 'next' instruction over a read (such as inp.nextToken ()), then nothing will seem to happen (the computer won't respond). That's because it's waiting for input from you, since it is executing an input statement. HOWEVER, the Java runtime generally reads an entire line at a time. So if you have an input loop: while (...) { inp.nextToken (); ... then GJDB will wait for input the first time you try to step over the 'nextToken' call, but if you then type a line with several tokens, like x - 3 it will NOT wait on the second and third iteration, because the program will still have leftover unprocessed input to work through. 8. Try to get your toString methods done as soon as possible. They are convenient for use in GJDB. For example, we stopped at the beginning of /** Returns THIS + Y. THIS is not affected. */ public Polynomial add (Polynomial y) { ... you can look at this and at y with main[0] p y.toString () main[0] p this.toString () or even main[0] p this + "+" + y Of course, these are less useful if toString doesn't work properly.