In this assignment you will practice
In this homework, you will begin creating many useful classes for our end goal of making a chess database!
Ply
Move
Ply
and Black’s Ply
.ChessGame
Move
s.Classes:
Ply
Piece piece
Square from
Square to
Optional<String> comment
Move
Ply whitePly
Ply blackPly
ChessGame
List<Move> moves
Move getMove(int n)
: returns the nth move.List<Move> filter(Predicate<Move> filter)
: Returns a list filtered by the predicate. Must not change moves field.List<Move> getMovesWithComment()
: returns a list of moves with comments (if either or both Ply has a comment). Must not change moves field. Must call filter
with a lambda.List<Move> getMovesWithoutComment()
: returns a list of moves without comments (if neither Ply has a comment). Must not change moves field. Must call filter
with an anonymous inner class.List<Move> getMovesWithPiece(Piece p)
: returns a list of moves with a piece of this type (if either Ply uses a piece of the same type as p). Note: the pieces don’t have to be the exact same but only must be the same type (both pawns or both queens etc.). Must not change moves field. Must call filter
with an instance of an inner class.Important:
getMovesWithComment
, getMovesWithoutComment
, getMovesWithPiece(Piece p)
must use filter
with a lambda, an anonymous class, and inner class respectively.
If there are any classes that you are unfamiliar with (e.g. Predicate or Optional), look them up in Javadocs. Make the visibility of all the methods and fields as you see best fits good programming style.
Here are links to the approved solution. Feel free to use it instead of your own code. Remember JavaDocs are still required.
Checkstyle deduction will be capped at 50 points for this homework. Use the -a flag when running checkstyle! JavaDocs will be counted for this homework.
Run this in the folder that has your java files:
java -jar <path-to-checkstyle.jar> -a *.java
Submit code that compiles!!!
Non compiling code will receive an automatic zero.
Ply (15 Points)
Move (10 points)
ChessGame (75 points)
getMove()
(10)getMovesWithComment()
(15)getMovesWithoutComment()
(15)getMovesWithPiece(Piece p)
(15)filter(Predicate<Move> filter)
(15)Submit each of your Java source files necessary for ChessGame to compile on T-Square as separate attachments. When you’re ready, double-check that you have submitted and not just saved a draft. Download each file and compile them to assure that nothing went wrong with the submission process.
Files needed:
Practice safe submission! Verify that your HW files were truly submitted correctly, the upload was successful, and that your program runs with no syntax or runtime errors. It is solely your responsibility to turn in your homework and practice this safe submission safeguard.
This procedure helps guard against a few things.