Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Homework for Spring 2012

Homework #1: Manipulate Pictures


Write two new methods in the class Picture that implement some kind of image manipulation.The two methods can not be the same. You must use a for loop in one method and a while loop in the other! The picture that gets manipulated should be the target that receives the method (i.e., this). For example, if you implement the method "mytweak()", then you'll use it on some picture somePicture.mytweak(), and you'll expect the picture somePicture to change. (Don't bother returning a DIFFERENT picture for this method. In other words, we expect both of your methods to be void methods.)

What manipulation that gets implemented is entirely up to you: Increasing blue while decreasing red, flipping vertically, posterizing, etc. You must implement something NOT already implemented in the class Picture. You can use the methods that are there as examples, but do not make any calls to those existing methods to implement your new methods.

Turn in Picture.java file via T-Square. Name your methods something that makes sense for what it does and place those names in the top comments region of the Picture.java class definition. Place your methods at the bottom of the class definition, with a comment before it indicating what your method does.

Priscilla will compile your Picture.java file in DrJava and test it using the interactions pane. She will create an instance of a Picture, execute each of your defined methods on that Picture object and show() the results.

WHAT TO TURN IN


Grading Criteria


Homework 2

Modify Picture.java so that when run (i.e., running the main() method), a collage is generated and shown (via .show). Here are the specs that you have to meet:

Submit Picture.java as your turn-in. You must use good commenting style. You are bound by the honor code not to share code with anyone.

Grading Rubric



Homework 3: Write your name with turtle: Letter Turtle


You will need: LetterTurtle.java

For this assignment, you will be required to draw your name (at least four letters) using a LetterTurtle.

The Initials
You will be expected to draw the first four letters of your first name (if your first name is less than four letters, write your first name and the first initial of your last name). For me, Mark Guzdia, this means that I should draw the letters “MARK” (upper or lowercase) to receive credit.

The Shape of the Letters
We realize the difficulty of creating letters that have curves such as D, O, S, B to name a few. Those with initials that have curves may draw the “block” or “square” versions of the curved letters instead. Those wishing to attempt curved letters are welcome to do so for extra credit. Please see the extra credit section.

Extra Credit (+5 for each extra method)
In addition to the block form of the letters, you can choose 1 or 2 letters and write methods for the curved version. If there is no curved version of your initials, feel free to choose any curved letter to do. Thus for my initials “MARK,” I would have to write one method for the block version of “R” and a method for "M" and "A" and "K" to satisfy the minimum requirements. To receive extra credit, I could write a method for the curved version of “R”

Method Header
You will need to write at least a separate method for each letter. You should input the maximum height and width, and the letter should not be larger than that. The method names need to be appropriate so as to be self-documenting. The minimum requirement will be for both methods to be void, but non-void method will be accepted as well.

For example, the methods I would have to write would be something akin to the following:
  public void drawM(int maxHeight, int maxWidth) {
    //Method body in here
  }

  public void drawA(int maxHeight, int maxWidth)){
    //Method body in here
  }

  public void drawK(int maxHeight, int maxWidth)){
    //Method body in here
  }

  public void drawR(int maxHeight, int maxWidth)){
    //Method body in here
  }

Method Body
You will be required to do your drawing with the LetterTurtle on a World. To make the drawing easier to see, you need to change the Pen width of the LetterTurtle to something other than the default width of 1. The final resulting drawing cannot contain a visible LetterTurtle.

Useful Mathematical Values and Methods
When drawing your initials especially the curved ones, you will probably need some typical mathematical values and methods. You will find these useful values and methods within the Math class in the Java API:

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Math.html

For instance if I wanted to use the cos method and constant value PI, I could do something like the following:
  double value = Math.cos(Math.PI * 0);

Casting
Because a great deal of the LetterTurtle movement methods require int values as inputs and most Math methods return double values, it is necessary to cast. In general, one of the java compiler’s tasks is to make sure that data types match across an assignment statement and between the formal and actual parameters of a method, and to show a compilation error if these are not consistent.

When we cast a value to a different data type, we inform the compiler that we really do know what we are doing, and that it should not worry about type consistency. Specifically, if we cast a double to type int, we are promising two things to the compiler:
1. We believe the contents of that double result to be small enough to fit in an int, and
2. We are happy to discard the fractional part of the double that is not stored in an int.

Here is the same line of code previously given:
  double value = Math.cos(Math.PI * 0);

What if value was actually an int like so:
  int value = Math.cos(Math.PI * 0);

Just looking at the code, you know you would get an error, because the types on either side of equal sign do not match. Currently we have:
  int = double

We need the same type on both sides to get past the compiler. Because we need int for our LetterTurtle method, we are going to cast the right side of the equal sign to int:
  int value = (int)(Math.cos(Math.PI * 0));

Here we finally have the same type on both sides:
  int = int

It is important to note that to change a double to an int, the double is truncated at the decimal point. Essentially this means the decimal and everything to the right of it is thrown away. It is very important to note that does casting will not round the value up or down.

Examples (done in Dr. Java’s interactions pane):
  > (int)5.123
  5
  > (int)6.523
  6
  > (int)-9.791
  -9

Commenting
Though your method names will be self-documenting you should still comment your code. Place above each of your method names, comments about what the method will do. Also always place comments that include your name, email ID (gtx000x or jsmith3) and grading TA at the top of all the java files you submit.

Main Method
You should also include a main method within LetterTurtle to generate your name. You should move the turtle between each letter's drawing to space out the letters appropriately.

So putting it all together, my code would start to look like this:
import java.awt.*;

/*** Name:
 *Prism ID(gtx000x or jsmith3):* Grading TA:
 **/ 
public class LetterTurtle extends Turtle{
  
  public LetterTurtle(World w){
    super(w);
  }

 public void drawM(int maxHeight, int maxWidth) {
    //Method body in here
  }

  public void drawA(int maxHeight, int maxWidth)){
    //Method body in here
  }

  public void drawK(int maxHeight, int maxWidth)){
    //Method body in here
  }

  public void drawR(int maxHeight, int maxWidth)){
    //Method body in here
  }
  
  public static void main(String[] args){
  World w = new World();
  LetterTurtle me = new LetterTurtle(w);
  // Position turtle here for first letter
  me.drawM(100,100);
  // Position turtle here for second letter
  me.drawA(100,100);
  }
}


What to Turn In

How to Turn In

Grading Rubric



Homework 4: Use Weaving and Repeating to Create Music (Woven Music)


Using the methods developed in class to play with linked list of music, create a song.

You only have to use SongNode and have a single part with a single instrument. It does not need to autoplay!

You will create a class (with some cunning name like MyWovenSong) with a main that will assemble your song, then open it with showFromMeOn (or show–whatever you need to do open up the notation View on your masterpiece). Please put comments in your class:
  1. With your name, GT-email address
  2. Explaining what you're doing

Turn in to T-Square:

Please consider sharing your song (by saving out the MIDI) in the Gallery HW4: Woven Music-Spring12

Grading Rubric



Homework 5: Use Weaving and Repeating to Create A Pattern (Woven Images)


Using the methods developed in class to create a pattern of repeated images with PositionedSceneElement. You are going to write code like this:
PatternPositioned-Main.jpg

To produce images like this:
PatternPositionedSceneElement.jpg


You will be modifying PositionedSceneElement. Please put comments in your methods:
  1. With your name, GT-email address
  2. Explaining what you're doing

Turn in to T-Square:

Please consider sharing your image (by saving out the picture as a JPEG or PNG) in the Gallery HW5: Woven Images-Spring12

Grading Rubric


HW6: Doubly Linked Lists

For this homework, you are going to create a subclass of LayeredSceneElement called LayeredSceneElementDoubly which adds in previous links. LayeredSceneElementDoubly nodes should do everything that LayeredSceneElement nodes can do, but internally, they have a link to the previous node. See page 154 in the book for some discussion of doubly linked lists, and see the video http://www.cc.gatech.edu/~mark.guzdial/videos/sceneElementWithPrevious/ for an implementation of doubly linked lists with PositionedSceneElement.

Criteria that you must meet:

You will implement your LayeredSceneElementDoubly class with a PARTNER using PAIRED PROGRAMMING. THIS IS A REQUIREMENT. Any solo efforts will lose 15 points immediately. You can learn more about Pair Programming. In your comments, you must state who your partner is and state, "No more than 25% of the program code was written apart from one another. Each of us spent half of the time together at the keyboard, with the other one watching over and navigating."

Test code

Here's how we might test your code, and what the points will be worth. (I'm writing this freestyle, so beware of typos below. If there is casting to be done to make it work, we can fit that in.)

Picture ptree = new Picture(FileChooser.getMediaPath("tree-blue.jpg"));
Picture pdog = new Picture(FileChooser.getMediaPath("tree-dog.jpg"));
LayeredSceneElementDoubly node1 = new LayeredSceneElementDoubly(ptree,10,10); // 10 points for getting the class to work
node1.insertAfter(new LayeredSceneElementDoubly(pdog,20,10));
node1.getNext().insertBefore(new LayeredSceneElementDoubly(pdog.scale(0.5),30,10);
System.out.println(node1.getNext().getNext() == node1.last()); // Should be true. 5 points
System.out.println(node1.getNext() == node1.getNext().getNext().getPrevious()); // Should be true. 10 points for getting the links correct here
System.out.println(node1 == node1.getNext().first()); // Should be true. 5 points
Picture bg = new Picture(500,500);
node1.drawFromMeOn(bg); // Should work. 10 points
Picture bg2 = new Picture(500,500);
node1.last().drawFromMeBackwards(bg2); // Should work. 20 points.
node1.remove(node1.getNext()); // 20 points
// 20 points for not implementing anything in the subclass that could just be inherited from superclass.


Here's what the code might look like with all the correct casts


public class TestCode2 {

public static void main (String [] args){

Picture ptree = new Picture(FileChooser.getMediaPath("tree-blue.jpg"));

Picture pdog = new Picture(FileChooser.getMediaPath("tree-dog.jpg"));

LayeredSceneElementDoubly node1 = new LayeredSceneElementDoubly(ptree,10,10); // 10 points for getting the class to work

node1.insertAfter(new LayeredSceneElementDoubly(pdog,20,10));

((LayeredSceneElementDoubly) node1.getNext()).insertBefore(new LayeredSceneElementDoubly(pdog.scale(0.5),30,10));

System.out.println(node1.getNext().getNext() == node1.last()); // Should be true. 5 points

System.out.println(node1.getNext() == ((LayeredSceneElementDoubly)node1.getNext().getNext()).getPrevious()); // Should be true. 10 points for getting the links correct here

System.out.println(node1 == ((LayeredSceneElementDoubly)node1.getNext()).first()); // Should be true. 5 points

Picture bg = new Picture(500,500);

node1.drawFromMeOn(bg); // Should work. 10 points

Picture bg2 = new Picture(500,500);

((LayeredSceneElementDoubly)node1.last()).drawFromMeBackward(bg2); // Should work. 20 points.

node1.remove(node1.getNext()); // 20 points

// 20 points for not implementing anything in the subclass that could just be inherited from superclass.
}
}

Homework 7: Make a Movie


Use the same classes as in WolfAttackMovie, but tell a different story with different pictures.

Criteria


Turn in your animation class and all your JPEG files.

You MUST do this as a Pair Programming activity, or you lose 15 points. Include an honor statement with your partner's name (both of you turn in the same code, and collaborate with no one else but your partner) and a claim that you each typed in approximately half of the overall code.

Not a requirement: Please do generate an AVI or MOV and uploading it here: HW7: Digital movies you created - Spring 2012

Homework 8: Sprite Animation

Two parts to this assignment:

(65 points) A. Create a class SpriteAnimation that will hold a list of pictures (using any data structure you choose) and a pointer to the current picture.  A SpriteAnimation understands an add() method that takes another picture and adds it to the list of pictures.  Each time a SpriteAnimation is told to getNext(), it returns the picture currently pointed to by the current-picture-pointer, then moves the current-picture-pointer to the next picture.  When the current-picture-pointer gets to the end of the list, it moves to the start of the list. (20 points for creating the class with the right instance variables, 10 points for a working constructor, 10 points for a working add() method, 10 points for a working getNext() method that returns a picture, 15 points for getting the circularity right.

I'm happy for you to define getNext() in other ways, but here's what needs to happen:

(35 points) B. Create a main() method in SpriteAnimation that creates a sprite animation and fills it with at least four pictures.  Generate an animation (using FrameSequence) with at least 30 frames using any additional pictures you want and also using your SpriteAnimation instance. (10 points for creating a SpriteAnimation, 5 points for filling it correctly with pictures, 10 points for generating an animation using FrameSequence, and 10 points for making it at least 30 frames long.)

Bonus 10 points: Make your animation move around the frame.

You must do this assignment in a pair.


Homework 9: Add the Hunters


Modify the Foxes and Rabbits Greenfoot scenario (like how we did in the adding Corn video) to add a Hunter class.

There are three parts to this assignment:


  1. Implement the Hunter as described. Create three hunters and drop them into the Foxes and Rabbits simulation. Call this simulation "foxes-and-rabbits-and-hunters."
  2. If you already have a pretty good equilibrium with Part #1, you can skip Part #2 and move on to Part #3. Now, save a copy of your simulation. Create another version of this simulation, where you try to maintain more equilibrium. You are welcome to change any one variable in your simulation, such as decreasing the number of hunters, decreasing how far away they can see, increasing the fox likelihood percentage in Field (thus creating more foxes), increasing the breeding variables for foxes. Call this simulation "foxes-and-rabbits-and-hunters-balanced." In your comments in the class Hunter, explain what you changed and why you think it worked.
  3. Now make another copy of "foxes-and-rabbits-and-hunters." Give hunters the ability to shoot up to one fox or rabbit per turn (only one shot object per call to act()). Try to find a setting of number of hunters and variables on foxes and rabbits where this new ecology is balanced. Call this simulation "foxes-and-rabbits-and-omnivore-hunters". In your comments in the class Hunter, explain what you changed and why you think it worked.

Turn in a zip file containing all three scenarios.

Grading Rubric


You must do this as a pair (or triplet) or receive -15.

Homework 10: Disease Propagation and Public Policy


Do Exercise 16.10 on Page 430 in the book. Make sure that you do 3 runs of the initial condition, so that you can compare the health policies to the baseline.

Grading Rubric

Hand in your code, and also your report (as Word or PDF)

You must do this as a pair (or triplet, if necessary), or receive -15.

OPTIONAL Homework 11: Villagers with Images


This is an optional homework, for extra credit only. Any points on this go toward your homework grade.

Do Exercise 16.6 on page 429. Turn in a zip file with the classes you add to the Simulation classes (and any Simulation classes you changed), as well as the JPEG images that you use to represent the villagers and the NBD. (Each pair turns in the same zip file.)

Grading Rubric


There is an additional 20 points available! Implement the villagers and NBD as a Sprite Simulation (10 points each), using the class you created for HW8!