| All HomeworkHomework 1This was handed out in class. Homework 2This was handed out in class. Homework 3This was handed out in class. Homework 4The assignment in brief
- Fork and clone the project into Eclipse:
- Fork the repository at https://bitbucket.org/ferzle/blankpicture
by logging into your BitBucket account, going to the URL above,
clicking the large + on the left side of the page and selecting
Fork this repository.
Change the name to something like Smith Picture, where you replace
Smith with your name. Make sure to click the box for
This is a private repository, and click Fork repository.
- Import it into Eclipse:
Click File-->Import..., select Git-->Projects from Git, then choose Clone URI, enter the URL
from YOUR fork of the project
(which you can get by clicking the Clone link) in the URI field,
and click Finish.
- Draw a picture by modifying the PicturePanel class.
- Commit your changes back to BitBucket from time to time.
- 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.
- Zip up your entire project directory (probably called something like MyNamePicture, where MyName is your name).
- Hand in the zipfile using
Webhandin under assignment 235-HW4.
- If you did it correctly, it should say that you handed in various files
which should include MyGrade.txt and src among other files.
Make sure it lists at least those two.
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 Student Solutions
(including mine).
Several examples I and previous students wrote.
Download the file, unzip it somewhere on your computer, Open Eclipse, do File-->Switch Workspace and choose the directory you just unzipped.
Then do File-->Import, select General-->Existing Projects into Workspace, click Next, browse to select the directory you just unzipped.
A dozen or so projects show display in the window. Select Finish.
It should load a new workspace the dozen or so projects in Eclipse.
You can see the code and run them (Right-click their copy of InteractivePicture and select Run As--Java Application).
When you are done looking at them, you can switch back to your normal workspace.
- 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 8" (If the class is "blah") and the first hit is usually the API for that class (The "8" ensures I get the documentation for Java 8 instead of 1.4.2 or 7 or some other version).
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
- Zip up your entire project folder (Something like SmithPicture,
which should include the MyGrade.txt file (which you should fill out first!)
assuming you didn't do anything weird.
- 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 (a) improve the design of the simulation and (b) add a third creature. In the next assignment you will improve the GUI.
You can see an example of what a finished Homework 6 might look like by downloading and running FoxesAndRabbitsAndSasquatch.jar.
You might notice that 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.
Start with the code in the FoxesAndRabbits2020 project.
- Fork the repository at https://bitbucket.org/ferzle/foxesandrabbits2020
by logging into your BitBucket account, going to the URL above,
clicking the large + on the left side of the page and selecting
Fork this repository, and make sure to click the box for
This is a private repository, and click Fork repository.
- Import it into Eclipse:
Click File-->Import..., select Git-->Projects from Git, then choose Clone URI, enter the URL
from YOUR fork of the project
(which you can get by clicking the Clone link) in the URI field,
and click Finish.
Part A
Add the Animal superclass of Fox and Rabbit as suggested in the various exercises in the textbook (through about 12.50).
Make sure you move as many methods/fields up to Animal as you can (and as make sense). Also make sure you have removed every reference
to Fox and Rabbit you can throughout the code. (Hint: you probably can't remove the references within Fox and Rabbit since
they need to know what type of animal they are interacting with. You also can't remove them in the populate method. You can remove them from simulateOneStep, however. You also should now have one list of Animals instead of lists for each of Fox and Rabbit.
There are other places to remove them from as well.)
Note that the simulation should run exactly as it did before you made the
changes, so verify that it does so. The difference is that it is (hopefully)
better designed so that it is easier to maintain the code and you will
be able to more easily complete Part B.
Part B
For this part of the assignment you will improve the Foxes And Rabbits simulation by adding another creature.
Do not read or attempt this part until you have finished Part A since it might confuse or mislead you.
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.).
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.
Tips (for both parts):
Handing it in (for both parts)
Hand it in as follows (points will be deducted if you deviate from these instructions!):
-
Fill in the details of the MyGrade-HW5a.txt or MyGrade-HW5b.txt file
(depending on which part you are submitting) in your project (double-click it to edit it) with your self-evaluation. Make sure you provide the total
and a justification for each category. Your justification should be more than one or two sentences but less than half a page.
For part B, include a very brief description of the creature you added in MyGrade-HW5b.txt.
- In Windows Explorer, right click on the Foxes and Rabbits 2020 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.
Grades (For Part A)
Your grade will be based on:
Criteria | Points |
Correctness | 10 |
Design | 10 |
Style/Documentation | 10 |
Total | 30 |
Possible deductions
- Not following the directions for how to zip up and submit code. (-1 or -2)
- MyGrade-HW5a.txt not filled out or lacks enough detail. (-2 or -3)
Examples of things I will be looking for as I grade
- Correctness:
Does it compile (0 points if it doesn't!)?
Does it still work as expected?
- Design:
Did you correctly refactor the code?
Proper use of Animal throughout?
Removal of Fox/Rabbit where possible (replaced with Animal)?
Removal of code/field duplication wherever possible?
Did you over-refactor? (That's probably not a word, but I mean did
you move too much to Animal so that Fox and Rabbit are more similar
than they are supposed to be?)
- Style/Documentation:
Does your Animal class contain complete Javadoc documentation?
Is your code readable, with loops properly indented, etc.
(Hint: CTRL-SHIFT-F in each class before you submit it.)?
Grades (For Part B)
Your grade will be based on:
Criteria | Points |
Correctness | 10 |
Design | 10 |
Style/Documentation | 10 |
Total | 30 |
Bonus | 5 |
Possible deductions
- Not following the directions for how to zip up and submit code. (-1 or -2)
- MyGrade-HW5b.txt not filled out or lacks enough detail. (-2 or -3)
- No description of 3rd creature in MyGrade-HW5b.txt (-1 or -2)
Here is a more detailed breakdown of the grading criteria for Part B:
|
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 |
|
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 8
- The assignment: HW 8 (Word)
- Submit it using Webhandin 235-HW8. Submit as Word or PDF.
Homework 9
|