Mini-Assignment C: Fireworks

UPDATE 3-25-08: A small bug in Particle has been fixed.  The getYPosition() return xPosition. 

Due Tuesday, April 1st at 7:00 PM

Java concepts I want you to learn from this assignment:

Other goals:


Files:
miniC.jar
Particle.java
FireworksApp.java

Grading Standard:
Grading Standard

Intro:
This class is not designed to teach you the easiest ways to be a Java programmer.  Instead, it is designed to give you a complete understanding of a programming language and to teach you concepts that apply to many other programming languages. 

The ArrayList class mentioned in the book provides many shortcuts that may hamper understanding.  For this reason, you are NOT ALLOWED TO USED THE ArrayList CLASS for assignments or exams.  However, it is an excellent class that you may wish to use outside of this class.  I feel that there is many good concepts illustrated by the creation and use of this class.  Thus this assignment focuses on writing a class very similar to the ArrayList (ParticleList) and a class that uses the ParticleList (FireWorksController).

I am giving you a bunch of classes in miniC.jar.  In addition to that I am providing you with two java files: Particle.java and FireworksApp.java.

When you are finished, your program should display a window.  Every time you click the mouse, it should make a fire work where you click the mouse.  It should look a lot like this.

To get started, download miniC.jar and add it to the Java Build Path of your project just like you did with all the other .jar files in this class.  Also download Particle.java and FireworksApp.java and put them where your source code goes.  FireworksApp.java won't compile if you haven't created the FireworksController class.

The Particle class

A Particle is a colored spot that can move itself and draw itself.  I am providing the Particle class for you since it has a bit of math and pseudo-physics.  Instead of putting it in miniC.jar, I am giving you Particle.java so you can play with it and improve it if you'd like to.

I recommend taking a look at the code so you understand what is happening.  The code is not very complicated and it's well commented.

The ParticleList class

The ParticleList is just what it sounds like--a list of particles. 

Question:  Why are we writing a class that is a list of Particles?  why not just use Java's built in Particle array?

Answer: Java arrays can't change size, so it's a little difficult to add and remove elements.  The ParticleList puts all that code in one place.  In fact, if you modified this class slightly, you could use it to hold anything.  Then you could have a substitute for arrays that is more powerful.  That is essentially what an ArrayList is (which you cannot use for this course).

The key operations are accessing elements, getting the size, adding and removing elements.  There are a few other methods which you can find described in the javadoc.  When writing it, keep in mind that if someone provides bad input to your code, it should not crash.  If the try to remove a non-existent element, the code should ignore the request.  If they call get() with an invalid index, it should return null.  You may decide what to do if call add() and pass in null as a parameter.

You can right the class how you'd like, but you may want to consider these hints:

You won't be graded much for the efficiency of your code.  Most of the grade will center around whether it is correct. However, it will be much, much easier for both of us if you right your code in the right way.

The FireworksController class

You will also write the FireworksController class.  This class is responsible for making sure that the particles that make up the fireworks are created, drawn, moved and removed correctly.

In addition to the constructor, there are three methods--makeFirework(), paintAll(), and moveAll() .  In order, they create, draw and move the fireworks. 

The FireworksWindow class, which I'm providing you with in miniC.jar will determine when each of these need to happen and will call the methods appropriately.  It might be easiest if you don't worry about when these methods are called--just make sure they do the right thing.  However, if you are curious, everything is drawn, then moved, then drawn, then moved over and over very quickly.  This produces the illusion of a moving picture.  The makeFirework() method is only called when the mouse is clicked.

Here are some hints:

The FireworksApp class

This simple class is a main method with only three statements.  I've provided it for you.  Once you have written the two classes, the class should compile and you should be able to run it.

It creates a FireworksController object, creates a FireworksWindow to control that object, and shows the window.

Extra Credit

It's not hard to earn a little extra credit on this assignment. 

The application I described to you is a little plain, and I encourage you to play around.  You can improve it how you like, but I'll give you some ideas:


I'm interested in insightful comments about why you wrote the code the way you did.  How do you deal with resizing the array?  When do you resize?  Is your array ever partially filled?  If so, how do you track which elements are valid?  How do you deal with removing Particles from a ParticleList?  When do you remove Particles? What constants did you choose and why?  I can give you extra credit if you can demonstrate that you fully understand your code.

I'd also be interested in some thoughtful comments about the assignment in general.  How could this assignment have been made easier?  Harder?  How could it have been put together better?  Worse?  Why did I design things the way I did?  How could you make the ParticleList class more useful?  What challenges did you face and how did you overcome them?  I'm willing to offer some extra credit if you can demonstrate that you fully understand the assignment.

If you want any extra credit, turn in a file called extracredit.txt.  That file should contain an explanation of how you improved your code and any analysis that you have for your code or the assignment.

Turning this in

Be sure to follow the course style and commenting guides--lots of people lost points here and they are the easiest points to get.  If you work in pairs, follow the pair programming guidelines and have BOTH partners send me a readme.txt.  Do not use the course handin program, since it isn't set up for the mini-assignments.

Recall that the course policy is not to accept late work.

The files I want from everyone are:
ParticleList.java
FireworksController.java

If you want any extra credit:
extracredit.txt


If you modified Particle.java in any way, I want that:
Particle.java

Pair partners:
README.txt from both partners

I don't want javadoc or any .class files.

Please email the files to Tim Bahls.  Send them to bahls AT wisc.edu.  You can zip them into one file if you wish.

Last updated 3-19-2008