Assignment 8: "Interfaces"
Handed out: Tuesday, November 8, 2016 Due: Before you leave for Thanksgiving! (i.e., Friday, Nov. 18, 2016) Purpose: Learn
- Review: how to write your own class,
- Review: how to make objects of your class in the controller class,
- New: how to use a Java Interface as a "contract" between class programmers,
- Review: how to use public methods in your class as a way to communicate between objects
Assignment:
- Download this code and uncompress (extract) it. (or download the files individually here).
- Look at all three source code (.java) files: Target, Tester, and Button.
- "Target.java" specifies the Interface between targets and the game. You must write a class, whatever you want to name it, that implements the Target interface. This means that your class must have an instance of each method in the Target interface. See the Target.java file for the list of methods (just the method signature is provided) and for comments on what each method should do. You must write the method bodies, such as the paint method body, the changeLoc method body, the move method body, etc. to allow your Target to be used in the controller object (which is the applet) in Tester.java.
- What to Modify:
- Target.java: Do not alter the Target.java file! That is the "contract" between us, and I will be using the Target interface as written in the file, so that my MODIFIED controller class (Game) will work with your targets.
- Tester.java: You should change here the first three lines of the "public void init()" method, in which three objects of JeffTarget are created. Change "JeffTarget" to the name of your class. And make sure that your .java file is in the same folder.
- And of course, as described above, you must make your own class that implements Target. Create a new file, e.g., "JeffTarget.java". In it put the usual import statement, then "public class JeffTarget implements Target" (change the name "JeffTarget" to your class name!), and below that goes your code, in curly braces, to include state var. declarations and methods, as usual.
- See the given .java src code files for additional guidance in the comments.
- Style: Indent, and comment (a main comment plus comments for each logical "block" of code, such as loop, method, if-then-else construct),
- Email your source code to me, just the ".java" file with your class, please. I do not need Tester, Button, or the Target.java interface file. I will use my own version of Tester!