Introduction
:
,,if(,),
,,
:
,,,,,
Requirement
Programming Assignment 5 ( 100 Points )
Due: 11:59pm Thursday, October 27th
README ( 10 points )
You are required to provide a text file named README, NOT Readme.txt, README.pdf, or README.doc, with your
assignment in your pa5 directory. There should be no file extension after the file name “README”. Your README should
include the following sections:
Program Description ( 4 points ) : Provide a high level description of your program. Describe what your programs
do and how you can interact with them. Make these explanations such that your grandmother or uncle or
someone you know who has no programming experience can understand what this program does and how to use
it.
Write your README as if it were intended for a 5 year old. Do not assume your reader is a computer science
major.
Short Response ( 6 points ) : Answer the following questions:
Vim related questions (keyboard commands only – no mouse actions, ASCII characters only):
1. In vim, how do you move the cursor to the end of a line with a single command? To the beginning of a line
with a single command?
2. How do you highlight/select a line in vim?
Java related questions:
3. What does the keyword static mean in regards to variables?
4. What does the keyword static mean in regards to methods? Provide an example use of a static method.
5. What is overriding? Give an example from a previous/current assignment.
Unix related questions:
6. Using the cut command, how do you extract out only the columns 5 through 13 in a file named foo?
STYLE. ( 20 points )
Please see previous programming assignments. A full file header for your README is not needed, but you still need to
put your name and cs11f login at the top. However, all other style. guidelines apply to all the files ( e.g. over 80
characters apply to READMEs as well. )
You will be specifically graded on commenting, file headers, class and method headers, meaningful variable names,
sufficient use of blank lines, not using more than 80 characters on a line, perfect indentation, no magic numbers/hard-
coded numbers other than zero and +/-1, and use of accessor/mutator methods to access private fields (getters and
setters) where specified.
CORRECTNESS ( 70 points )
You are asked to create an interactive 3 x 3 puzzle game for pre-schoolers. The player has to drag the puzzle pieces on
the right to the correct location on the left to form. a complete image. This assignment does NOT involve ActiveObjects
or require a paint() method. The correctness of this assignment is based on meeting the required functionalities listed
below.
Part 0: Overview BoardPieces PuzzlePieces
We have a 3 x 3 puzzle, which gives us 9 puzzle pieces that are movable on the right. They can be dragged
anywhere on the canvas, but not off the canvas. On the left, we have a 3 x 3 board. After a puzzle piece is dragged
onto its correct location, the puzzle piece is “locked” into the board and is no longer movable.
The reason “locked” is in quotes is because the puzzle piece is actually not locked. We created this illusion by
having two different types of Pieces here: PuzzlePiece and BoardPiece. When a PuzzlePiece (movable piece on the
right) is dragged onto a BoardPiece (fixed piece on the left), your program will do some verification to see if they
match. If so, it’s going to hide the PuzzlePiece and reveal the BoardPiece with the same image as the PuzzlePiece.
So it may seem like the PuzzlePiece is locked in place, but it’s actually a different BoardPiece that’s displayed on
the canvas. Now that we know the basic idea/hack behind this game, how do we implement it?
Part 1: Useful Interfaces
Take advantage of interfaces! We have two different kinds of Piece types here, but they share a lot in common.
We’ll implement the Piece interface later in PuzzlePiece and BoardPiece classes.
1. The Highlightable interface is used to draw borders and highlights around each piece:
import java.awt.Color;
public interface Highlightable {
public abstract void showHighlight( Color color );
public abstract void hideHighlight();
}
2. The Hideable interface is used to hide and show pieces:
public interface Hideable {
public abstract void show();
public abstract void hide();
}
3. The Piece interface, which extends the two interfaces above an㱥⼠㹦⸠ ♰㭢⁰†♩㭴†㱢 ⼾㸍ഊੰ†
䴻†Ɫ†‾㱰⽩㹣ഠ†⁴†⁃⸩㰻⼠㸯ാ㍩㩣†㰠⁴⽉㹤ന☾㭬†⁴ⰻ‼† ††⁵⸠䍲㰠⁐⽩㹥ൣ䍡⁐‼⠾⤍ †††⁰䅬䵴䙥㱴⽡㹣ਮ⁸‾⁰㝵㍢㕬㍬㡡び⹐㱩⼠㹩൭ੰ㍴㨠⁐䝩䤠㱬⁰⼻㸠ൽ਼‾ㄍ《ぅ⁐ㅩづっ⁴⼼⼠⽵䅬㔻ⴠ⽩
㱥⽧㹥ഠ〠㡰⡳†の⸠Ⱨㅯⱴ†♴㭣⥯㱳⁵⽣㹴൯ੲ䤩 ⁵†Ⱐ‸†䥦⡴⤠⁴⁴†⁴⡯⁉䝄䥲㰠⽣㹥ഠ䍩⤯⸾䘊⁵㩮㱴†⼨㹡ഠੌ䥴⡯♢㭴ち♰㭴⥳㬠㱴†⽣㹥൮ੴ†⁴㤠⁰䥵†⡳䥴⁵⥣†䤨⁶㤠⁴㰩⽳㸠൯੮䥬⡆⥲ⱡ⁒†‼‾⁴䥤⡰⥳†䥥㱥†⼨㹴൨††䥴
⁆⁴䉩⽯♥㬠Ⱐ㱴⽱㹵൯䉥⼠☊㬠Ᵽ⁵䥥†䥂⁐㱯⼠㹯൮੬㍰㩡⁹䰠㱵⼼㹢൲ਠ ⁴䉯⁂⁺㱸⁰⽬㹥ഺ਼䅢Ⰽ ⁂ㅥ㠠Ɱ†⁃⁶‼䱢Ᵽ㱣⽳㸠൷੩䉬 …†
㱡⽳㹳ഠ䱮†⁶㩒㱥†⽯㹢൪⁴⁴䥥䕡䍣䕨䕥䌮䱢㴠 ㌾㬍 ⼦⽢⁵††⁺㱨†⽴㹨ਠ⁆䥒䕥䍣䕴䕧⁴㴮†㍳㭨⽷⼨
†‼††㱨†⽴㹨ਠ⁗†⁈䱩䕧䄩䌠䥷䝥㴠⁷㉥〠㭷⽮⽴†⁰⁹㰠‼⽢㹲ഠਯ䱩䕳䙮䘠䕨†㵣㍲㕲㕥㭣⁴⼠⽳⁰⁴
††㱡⼩㸮഼†⁐䉵䅺䑥䵩䅥䝥䤠⁵㵬㈠㕨㭩⽥⼠⁴㱨†⽨㹩⁴䉨䅮䐠䵮䅬䝳䥳†㴯‾㐍《㭹⽵⼠⁰†⁴㱴†⽣㹲 䥳䐨䔩䱩䕮䝐䡺⁺㵬ㅐどづ㭣⼠⽤㱮⽳㸠ൣ੯䉮†⁖㱤⽴㹨഼†㴯‾䈍䅴䑡䴠䅰䝥䥣⁈⭩䤺䐠䕵䱥䔠䝩䡩⡥╡䤦䕲䍳䕱䕳䍯䱴⥡㱩
⼩㸠൭㱤†⽣㹯൮ੴ㵮䈨䄠䑥䵨䅯䜠䥩⭡䥐䑩䕥䱥䔠䝥䡵⡥†⽡†䥩䕴䍴䕬䕲⥭㱲⽯㹧൩†⁺㱥⼬㸠൹੯†㵤䱱䕵䙴䘠䕡⁴⬠䱥䕲䄠䍳䥯䝶†⡴╳†䥯䔠䍱䕵䕬䍢䰠ㅴ⤼㱢 ⼾㸍ഊ⭲䥧䑩䕮䰠䕴䝥䡐⁵⁺⡺═䥣䕥䍳䔠䕳䍥䱯⥵㱧⁴⽯㸠൴੨㱯⽐㹩㴠䱥䕹䅴䌠䥬䝣⡤⽮†䥵䕴䍯䕭䕣†⭉ㄠ⥹†䥲䑥䔼䱲䔠䜾䠊⁴⩨⠠⽡⁹䥲䔬䌠䕹䕡⥯㰦ⁱ⽵㹯഻ੴ††††⁐⁺䥬†⸠⁷㱥⼠㹓൯ਠ††††☠㭤†⸍㰊⽳㹩൮੧䈠††††Ⱐ⁰††⁺†♤㭮ℍ☊㭮⁴
㴩㌠㕉㕦㰠⼠㹣੮†㴠⁴⁐⁺†⁷䈠䥸†㔠㕴䠬㱹⽤㹱൵੯Ɐ…†⁂⁗⡨⁷† 㱥⽦㸠൴੨⥮㱡⽤㸠൩੮☠㭸⸍ †䉬††⹐ⁱ
†䥥㱨⁐⽵㹺ൺ੬䱣†⁴⁂䉯‼†⁴†⁵ⁱ⁄††㱡⽧㹮䈠‼‾…䤨⁴⁴⁵⁵䱥⁴‼ 䈦⁃⁴䕴㱳⽥㸠ൣ䉮䤠䑐…※⁂†㰠†⽮㹯൴੨䙩†Ⱳ†⁵† 㱴†⽣㹲⁶†⡡⥲†䱲䑷䌠‼ ⁵㱲⁵⽺㹺൬䤠䝰 †ち㡢⁐‼†⁙㱨⼠㹡൬੬♧㬮䥡Ⱳ ††⁹††㱩⁹⽯㹵ഠੰ†Ɐ⁴⸾☼㬍⁹ⱶ㱴⁴⽯㸠൹੯⁹† †⁴⁵⁹†㱡⽧㹮൭⁴♡㬠†㥡⁵ⸯ‾䤠䑩⁷⁷†㱲‾⼍㸊ൖ‼ ⁶†⁶⁵⸠㰯 ⼾㸠ൣੳ‱⁹ 㡳Ⱶ⁰†䵳䄠䴠䙲䥤䔠䍩䕮†䥲Ɽ㰮⼠㹷൩੬䵬䄠䵴䙥䥮䕹䌠䕬⁴㥩⁵ †⁵†ⱦ⁹⁰䴠䅹䵨䙫䥨䕩䍣䕨♩㭯⁵ㄠⱨ㱣⽳㹦൵੬††⸠㱭⼠㹳൵ੲ䡥ⅰ⁴⁹‼ 䈾†⁃ †䈠‼㰍⽡㹲⸼䜊䥩‼⡢ ⥧⁶‾⁐†㱪⼼㹢൲ਠ⸮ † 㨠⤯㰾⁰⼳㸮൪ੰ†㌯㨍 䑰㰼†⼯㸾ਊ䉰䅰㕧ⰼ‾⁰⁰†⁁䵥⠾⤍Ⰺ⁒䵄䑲⠍⤊Ɐ⁴䵡⠍⤊⹅⁸†⁴㰠⁰⽯㹩൮ੴ›⁎⁰††††⁰⁴㱥⽭㹥ഠ੦ ⁓⁹ⱹ⁒⁅⁴㰠⁵⼠㹨ൡ੶†⁄′⁴⁁††㰬⽥㸠ഹਠ㱳⽯㹵൬㌠㩩㰠†⽡㹥൲੩䡡♩㭕⁃‾⁄⁁†††⡳⥵⁴㱲⽬㹹ബਠ†⁴㼊‹♥㭥††ⱨ⁴䥯☠㭥
⡳䡩䥤㩂†䵳䑴⡲⥲⥹⸠㱡⁵⽴㸠ੲ䉡䥮♧㭢 †⁶
⁵†⸼†Ⱐ⁗㱮⼠㹛ലਮ†⁴‼ ⁴⁵㕯〻⁴⁴㕯ば†⁰⁺䈬Ⱳ†㰠⁴⼠㹡൬††☊㭲♥㭴†䉭⡩††⡣⥫⥩䠠ⱷ†㱣⁰⽬㹥൴☠㭭⁺†䉷…††䍃⠩⤠†㰠⽮㹧൳ਠ‾ⁱ⁴⡩⥴䈠†⹔䥸††䉥㱡†⽳㹨൯ੵ††⁔⁓⁔⁐䅲䐯‾⁁⁅‼⡢䥬䑬⥰ⰻ⁈⁅⁎ 㰀 ⼀㸀ഀ☀㬀☀㬀 ⸀ 䄀Ⰰ ☀㬀☀㬀㰀 ⼀㸀ഀ 㰀 ⼀㸀ഀ 䈀 㰀 ⼀㸀ഀ ⸀ 䐀☀㬀㰀 ⼀㸀ഀ 㰀 ⼀㸀ഀ 䈀 ⴀ㰀 ⼀㸀ഀ ☀㬀 㰀 ⼀㸀ഀ ℀㰀 ⼀㸀ഀ ㌀㨀 㰀 ⼀㸀ഀ䄀 ☀㬀 䤀 ℀ 䠀 㼀 㰀 ⼀㸀ഀ ⸀ ☀㬀☀㬀⸀㰀 ⼀㸀ഀ 䤀䐀 㠀Ⰰ 㰀 ⼀㸀ഀ☀㬀☀㬀⸀ ⸀ 䄀 Ⰰ 㰀 ⼀㸀ഀ 䈀 㤀 ⸀ 㰀 ⼀㸀ഀ ⸀㰀 ⼀㸀ഀ䄀 Ⰰ ☀㬀 ⸀㰀 ⼀㸀ഀ㰀 ⼀㸀ഀ Ⰰ 㨀㰀 ⼀㸀ഀ㸀 ⴀ ⸀⼀