| 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.
- Modify index.html by changing the title and (if necessary) the width and height.
- 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), index.html,
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.
- Go to the Student Solutions page and verify that your code is there and that your applet runs.
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 should:
- 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).
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
applet 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
- Several examples I and previous students wrote
- BlankPicture The starting code. You will actually get it from elsewhere (SVN), but can also see it by following the link. This includes two classes (and perhaps a few other
files which you can sefely ignore.
- PictureApplet is the main class which allows you to run the program as an applet or application.
You should not need to modify this class.
- PicturePanel is the class that does the drawing, and you should certainly modify this one!
- Past Solutions (including mine)
- 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.
- 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.
- index.html, modified as necessary.
- MyGrade.txt with your self-assessment.
- Remember to submit with
Webhandin under assignment 235-HW4.
- Go to the Student Solutions page and verify that your code is there and that your applet runs.
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
-
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.
- Use Webhandin with assignment 235-HW5 to submit the zipfile you just created.
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.
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.
|