| All HomeworkHomework 1This one was handed out in class. Homework 2This assignment was handed out in class. Homework 3This assignment was handed out in class. Homework 4The assignment in brief
- Copy/Checkout the BlankPicture project from the SVN repository (We'll do this in class).
- Draw a picture by modifying the PicturePanel class.
- Commit your changes to the SVN repository from time to time. Refer to the SVN and Eclipse Examples as needed.
- Change the width and height of the window (if you want)
and the title on the frame (this you should change) near the top of InteractivePicture. You should make no other changes to that file.
- Fill in the MyGrade.txt file. Specify the score you think you earned in each category and briefly justify.
- Hand in all of your java and class files
(including the ones with symbols and numbers in the name)
and MyGrade.txt
using
Webhandin under assignment 235-HW4.
You can submit the files separately or put them in a zip file (with no directories--just the files) and submit that.
Purpose
The purpose of the first assignment is to
- Help you refresh your memory on Java programming
- Familiarize yourself with the
Eclipse IDE (integrated development environment),
- Learn how to use the Java API (application programming interface).
There is not a serious design component to this assignment, and at the surface
it does not appear to be closely related to the main concepts of the course.
However, it is meant to be a fun assignment to get you back into the swing of Java programming, and it turns out it does have a little to do with a few of the topics we will talk about.
Assignment
For this assignment you need to finish the implementation of the class PicturePanel.java that draws a picture.
I will let you decide exactly what you want to draw, but be creative.
You can draw a picture of yourself, your dog, a car, a park, etc.
Your drawing should be a reflection of yourself.
I can help you brainstorm ideas if necessary.
At a minimum, you must:
- Have at least several dozen objects (circles, lines, text, etc.).
This does not include stuff drawn in loops. In other words, you should have at least 24 statements
in your code like drawOval, fillRect, etc.
- Utilize several colors.
- Have some text, including your name in the lower right corner. Use different fonts and styles.
- Use several loops, and at least one nested loop (That is, a loop within a loop) to draw something.
- Use at least a few if-then-else statements.
- Use an array, ArrayList, or another simple data structure.
- Use at least two methods.
- React to at least 2 different mouse events. It does not count to react to "clicks" with both mouseClicked and mousePressed.
Use another interaction like dragging.
(Note: There are two sorts of mouse events:
MouseEvents and MouseMotionEvents. See below for more about these.)
- Create one or more new classes (not including listeners).
- Change the title of the frame so it relates to your drawing.
The more different sorts of objects you use, the better.
Your grade will be based not only on how creative you are,
but how much effort you put into learning some
things about the various parts of the Java API mentioned below.
An assignment which meets the expectation will receive 24/30.
Scoring higher than this will require you to go beyond the minimum requirements.
If you have some prior experience with Java, or learn quickly, try to make your
application fancy with animation, or adding some functionality. For instance, you
can ask the viewer to input some information, and modify the drawing based on the input.
You should not use BlueJ for this project.
Use Eclipse instead.
Make sure to update the documentation.
Remove my helpful comments and add appropriate comments to each class and method, using Javadoc-style comments.
Also add inline comments within longer methods to describe what portions of your code are doing.
Resources
- Past Solutions (including mine) Several examples I and previous students wrote. You may have to adjust settings or do something else to get these to run. Java recently changed security settings and applets are now much more difficult to run.
- TimerExample A simple example of using a timer to do animation.
- Java API
Here are the classes that will be of most interest to you for this assignment (these link to the Java 6 versions of these classes,
but they should be not much different than the Java 7 or 8 versions).
- Graphics
The main class you will be interested in. You draw using the methods from this class.
- Color
A class you may be interested in if you want to create your own colors.
- Font
A class you may be interested in if you want to do anything fancy with Fonts.
- MouseMotionListener
An interface for mouse motion events
- MouseListener
An interface for mouse events
- MouseAdapter
An adapter that implements the MouseListener interface. Extend this class as a way to handle mouse events.
Simply override any of the 5 methods to have it react the way you want.
- MouseEvent
The event passed to the MouseAdapter/MouseListener. Notice it allows you to determine the
x and y coordinates of the mouse position, which button was clicked, etc.
- Java Fonts
A simple applet that shows you what certain fonts look like in Java. You might find it useful.
- Google (link includes a sample search). Search for whatever you need help with. For instance
"Java fonts" or "java font choices" or "java create colors", etc. When I am looking for a java class, I search for "java blah 6" (If the class is "blah") and the first hit is usually the API for that class (The "6" ensures I get the documentation for Java 6 instead of 1.4.2 or 5 or 7).
Grades
Grades will be based on the following chart. See the Grading page for how to interpret these categories.
Criteria | Points | Details |
Correctness | 10 | Each requirement met (8) and it runs (2) |
Style | 6 | Reasonable variable/method names, methods make sense, and code formatting (2 each) |
Documentation | 6 | The class, each method, and code is documented (2 each) |
Learning Gains | 8 | Used classes, made an elaborate drawing, included extra events and methods (especially if it involved keyboard and other event types), used other new things (2 each) |
Total | 30 | |
Handing it in
- Don't forget to hand in:
- All of your java files
- All of your class files, including those with $s in the name.
- MyGrade.txt with your self-assessment.
- Remember to submit with
Webhandin under assignment 235-HW4.
Homework 5The next two assignments will be related to the Foxes And Rabbits simulation. In this assignment you will add a third creature. In the next assignment you will improve the GUI. You can see an example of what a finished Homework 5 might look like by downloading and running FoxesAndRabbitsAndSasquatch.jar. (There is only 1 Sasquatch and he eats everything around him. As you can see by running this, he doesn't really affect the simulation much.)
For this assignment you will improve the Foxes And Rabbits simulation by adding another creature.
The third creature must not be another animal (i.e. it cannot be a subclass of Animal), and you should try to think of a creature that will affect the simulation in some significant way.
You should perform some of the suggestions from the textbook to create an Actor class, refactor the code accordingly, and add your third creature.
Some ideas for creatures include a human, a virus, a dragon, weather, fire, etc. It must act different than both the fox and the rabbit in some significant way (e.g. never dies, doesn't breed, kills everything within 1 or 2 squares (but as Sasquatch demonstrates, having one such creature is boring), kills everything in its row and column, teleports, etc.).
If you did a similar assignment to this in CSCI 225, you should implement a different sort of creature for this assignment and you should not use any of that code. You will learn more this way, and isn't that the point?
You should start with the code available at http://svn.hope.edu/CSCI/cusack/Foxes And Rabbits 3.
Follow the instructions from the appropriate section of SVN and Eclipse Examples to get the code.
Note: This code is based on an earlier addition of the textbook and has been modified to make the next assignment easier.
Tips:
-
Use what you have learned about inheritance and polymorphism to implement this properly.
-
Do not just sit down and start programming—it will be much easier to implement if you first sit down and think about design.
For more of a challenge (and bonus points), do any of the following:
- Make the drawing of the simulation a bit fancier.
You can draw actual foxes and rabbits, or use little circles for bunnies
and triangles for foxes or something similar.
- Add a fourth creature that is significantly different than the others.
Your grade will be based on:
Criteria | Points |
Correctness | 10 |
Design | 10 |
Style/Documentation | 10 |
Total | 30 |
Bonus | 5 |
Hand it in as follows (points will be deducted if you deviate from these instructions!):
-
Fill in the details of the MyGrade-HW5.txt file in your project (double-click it to edit it) with your self-evaluation. Make sure you provide the total (out of 30) and a justification for each category. Your justification should be more than one or two sentences but less than half a page.
Also include a very brief description of the creature you added.
- In Windows Explorer, right click on the Foxes and Rabbits 3 folder and select Send to-->Compressed (zipped) folder.
- Name the zipfile whatever you wish and make sure it is a .zip file and not some other format.
- Use Webhandin with assignment 235-HW5 to submit the zipfile you just created.
Here is a more detailed breakdown of the grading criteria:
|
third creature works | 2 |
third is not animal | 3 |
third different than others | 2 |
program runs | 3 |
Total Correctness | 10 |
|
Actor class implemented and used | 2 |
fields and methods properly placed in hierarchy | 2 |
no unnecessary special code (e.g. in simulateOneStep) | 2 |
cohesion (no weird methods or fields) | 2 |
no unnecessary code duplication | 2 |
Total Design | 10 |
|
Javadoc for all classes/methods | 3 |
documentation in code where necessary | 2 |
good class, method, field names | 2 |
code organized, extraneous code removed | 3 |
Total Style and Documentation | 10 |
|
4th unique creature (bonus) up to | 2 |
improved graphics (bonus) up to | 3 |
Total Bonus up to | 5 |
|
You might also want to know common reasons for miscellaneous deductions:
- Not following the directions for how to zip up and submit code. (-1 or -2)
- No description of 3rd creature in MyGrade-HW5.txt and/or MyGrade-HW5.txt not filled out or lacks enough detail. (-2 or -3)
Here are some of the common mistakes related to the main grading criteria that past students have made:
- The fact that everything will probably implement location stuff the same way may suggest an abstract class.
- Your third creature is virtually identical to Animal--it has all of the same fields and methods. Thus you didn't really implement something different than an Animal, you just put is somewhere else in the hierarchy and duplicated code.
- Your third creature is almost identical to Rabbit and/or Fox.
- Special cases for your third creature in simulateOneStep may indicate a design problem.
- Since your creature can't die, why is setDead in Actor?
- Since your creature can't age, why are the age related methods in Actor?
- Don't leave old documentation in your files. For instance, if you copy a class, update all of the documentation. Add your name to classes you created. Do not include the name of the textbook authors in classes you created.
- Remember to use Javadoc comments for every class and every method.
Homework 6For this assignment you will improve the Foxes And Rabbits simulation from Homework 5 by adding more buttons. The application should have the following things.
- One button that will run 1 step of the simulation.
- One button that will run 100 steps of the simulation.
- One button that will run the long simulation.
- One button and associated text field to allow the user to specify
the number of steps to run.
You should deal with potential errors with what the user
puts in the text field.
- One button that will reset the simulation.
- A JMenuBar which contains
- "File->Exit" which exits the application
- "Help->About" which gives information about who wrote the application, etc.
(use the JOptionPane.showMessageDialog method for this).
To keep the simulation from being buggy, you should disable all of the buttons while the simulation is running.
Note: You can't just disable them at the beginning of the listener and re-enable them at the end because the simulation is run in a different thread and the listener will return almost immediately. But you can disable/re-enable them at the beginning and end of the run method in the thread. However, if you want to keep Reset enabled during a run so that it will stop the current simulation and reset it, you will also need a boolean field and related code in several places to deal with this.
The application should quit properly when the "X" in the upper right
corner is clicked. This is properly implemented in my version of the code,
but if you move the main JFrame somewhere else, you will have to make sure
you copy the WindowListener code.
You should continue with your code from Homework 5.
Note: In this version Simulator and SimulatorView have been slightly modified to make it a bit easier (the version in the book was not designed to make adding buttons easy). I should also point out that this code is based on an earlier addition of the textbook so the code may have other differences.
For more of a challenge (and bonus points), do any of the following:
- Allow the user to select parameters of the simulation like board width and height,
and creation probabilities. When the user hits reset, the newly generated board will
be based on these parameters.
- Allow the user to select the stats for each creature,
including max age, max litter size, etc. This will require modifying the code for
Rabbit and Fox, among other things.
- Allow the user to click on the squares to place rabbits, foxes, etc. One way to
do this is to have each click rotate around the options (rabbit->fox->hunter->empty->rabbit...).
Grading
Criteria | Points |
Correctness | 10 |
Design | 10 |
Style/Documentation | 5 |
GUI/Interface | 5 |
Total | 30 |
Bonus | 5 |
Handing it in.
-
Fill in the details of the MyGrade-HW6.txt file in your project (double-click it to edit it) with your self-evaluation. Make sure you provide the total (out of 30) and a justification for each category. Your justification should be more than one or two sentences but less than half a page.
- In Windows Explorer, right click on the Foxes and Rabbits 3 folder and select Send to-->Compressed (zipped) folder.
- Name the zipfile whatever you wish.
- Use Webhandin with assignment 235-HW6 to submit the zipfile you just created.
A more detailed breakdown of the grading criteria:
|
new buttons work: | 8 |
menu works: | 1 |
exit works: | 1 |
TOTAL Correct: | 10 |
|
GUI code organized and consistent: | 4 |
listeners consistent: | 3 |
listeners implemented reasonably: | 3 |
TOTAL Design: | 10 |
|
GUI element names are sensible: | 3 |
GUI code commented: | 2 |
TOTAL Style/Doc: | 5 |
|
GUI not a mess: | 2 |
disable buttons when necessary: | 3 |
TOTAL GUI/Interface: | 5 |
|
change size: | 2 |
individual stats: | 2 |
place animals: | 2 |
try-catch in input field: | 1 |
TOTAL Bonus: | 5 |
|
Deductions: |
no self-eval: | -3 |
Submitted incorrectly: | -3 |
|
Homework 7This was handed out in class. Homework 8This was handed out in class. Homework 9You got a copy of this assignment in class. Homework 10Download the following files:
The directions are in the first file.
|