HTW Berlin Medieninformatik HTW Berlin
Fachbereich 4
Internationaler Studiengang
Internationale Medieninformatik (Bachelor)
Info 1: Informatik I
Winter Term 2022/23

Christmas Fun

It's Christmas vacation time, you need an excuse to get away from relatives you haven't seen in a year, so you really, really need something to program. Here are some ideas for you to play around with!

  1. Now that you know how to do fixtures, use the Figures project to make a nice Christmas tree with presents underneath it. Make a new class ChristmasTree that uses the appropriate figures. I would suggest making the picture, putting it in a fixture, and then copying that code to the new class.

  2. Do you have younger brothers and sisters? Reprogram the tech support system to be a Santa Claus bot! It asks if you have been naughty or nice, and perhaps asks for what presents the child wants, giving appropriate responses. For example, don't promise a cat or a dog, but maybe a Frozen doll or a Lego set is okay.

  3. Bouncing Balls

    1. Download and install the Balls project from Moodle. Experiment with the Canvas by drawing some more lines, putting in some shapes or even text. The API is your friend.
    2. Draw a frame around the canvas by drawing a rectangle 20 pixels inside the window borders. Draw four lines to make the rectangle. Put this functionality into a method called drawFrame in the BallDemo class.
    3. Improve your drawFrame method to adapt automatically to the current canvas's size (that is, do not hard-code the size of the canvas into this method. To do this, you need to find out how to make use of an object of class Dimension. (Hint: check the API!) Test it by manually resizing the canvas and calling drawFrame again.
    4. Make a new method bounce that lets the user choose how many balls should be bouncing. Is it possible to have two methods with the same name? Use a collection to store the balls so that you can deal with one, three, or 75 balls at once. The balls should initially be placed in a row along the top of the canvas. But what kind of a collection? We know about ArrayList, HashMap, and HashSet.
    5. Make a new method bounceRandom that places the balls randomly anywhere in the top half of the screen.
    6. (For the really bored) Write a new method named boxBounce. This method draws a rectangle (the 'box') on the canvas, and one or more balls inside the box. For the balls, do not use BouncingBall, but create a new class BoxBall that moves around inside the box, bouncing off the walls of the box so that it always stays inside. The initial position and speed of the ball should be random. The boxBounce method should have a parameter that specifies how many balls are in the box.
    7. (For the exceptionally bored) Give the balls in boxBounce random colors. Include a method to change the size. Make balls that get larger and smaller. Make exploding balls that produce new ones when they disappear. Or whatever catches your fancy.

Brag Sheet

If you get something cool to work, submit it to the Brag Sheet in Moodle! This is a forum where everyone can see the cool stuff you did!


Copyright Prof. Dr. Debora Weber-Wulff
Questions or comments: <weberwu@htw-berlin.de>
Some rights reserved. CC-BY-NC-SA - Copyright and Warranty

The exercises are adapted from Objects First with Java, A Practical Introduction Using BlueJ. David Barnes & Michael Kölling, 2016