CS 157 Spring 2003               Assignment 4 – Some Basic Objects – using an existing class.                   100 points

 

Assigned: 02/05/2003

Due: 02/12/2003 (at the start of class – as will be the normal case)

 

Pre-Lab (Do Before Lab):  Bring an empty (or nearly empty) disk. Plan out sequence of statements needed for program.

 

Main Assignment:

 

We are writing a fairly silly program, because the concepts themselves are challenging at this point. You program will use the capabilities of the ChessPiece class provided on the assignments page on my www site. Your program will interact with the user, asking for info to be used to create two chess pieces (piece color (B or W or E (empty space)) and piece name (queen, rook, knight, bishop, pawn, king, or empty (no piece)). With what we have covered so far, it will be difficult to ensure that the info entered is valid, so don’t worry about that now. To keep your job simple for this early in the class, we will assume that the order-entry typists are infallible.  Create a chess piece using the info given by the user. Then, for each chess piece, display the piece using println, and show the results of running ChessPiece methods toString and getValue.  See the example below.

Put your name, e-mail address, and date in comments near the top (e.g.  /* Your Name */).  You will need to download ChessPiece.java from my WWW page. Change the package statement in the file to be appropriate for what package you put it in, otherwise you should not have to modify the file. Note, that on my WWW page, besides the java file, there is a documentation file. This is where you should learn about the class.  You will still need the Keyboard file (still obtainable from my WWW page  - or from last week). 

Compile the program and remove any errors. Ensure that the program runs correctly. It should run on any inputs (that shouldn’t be much of a problem with this straightforward a program).

               To avoid needless long waits, I recommend doing this on the c: drive, then upon completion, copying it to the a: drive, testing it there, creating an extra backup for yourself, then deleting it from the c: drive.

 

 

Sample Interaction:

 

What Color is the first piece? (W,B, or E for Empty)

B

What rank is the first piece? (king, queen, rook, ... or Empty)

queen

What Color is the second piece? (W,B, or E for Empty)

W

What rank is the second piece? (king, queen, rook, ... or Empty)

rook

The first ChessPiece is: BQ

The second ChessPiece is: WR

toString on the first ChessPiece returns: BQ

toString on the second ChessPiece returns: WR

getValue on the first ChessPiece returns: 10

getValue on the second ChessPiece returns: 5

 

Hand in: