Programming Exercises

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
Historical topic: Java appletsModern web browsers do not run Java applets. The Applet API was deprecated for removal before Java 25 and was removed in Java 26. Treat applet examples on this page as historical object-oriented/GUI examples; for new desktop interfaces use Swing where appropriate or JavaFX/OpenJFX.

created 01/01/03


Chapter 74 Programming Exercises


Note: You may find that appletviewer is a better tool to use with applet graphics than your Web browser.

Exercise 1

Modify the snowflake method so that different levels of stars are drawn with different colors. Use colors that are all close to pastel blue. Do this by changing the pen color based on the size of the star.

Click here to go back to the main menu.


Exercise 2

Implement the blizzard program: draw a few dozen randomly positioned snowflakes of a few random sizes and a few random colors.

Click here to go back to the main menu.


Exercise 3

Write a java applet that creates the following figure:

Embedded Java applet removed: modern browsers do not support Java applets. The surrounding source code is retained for historical study.

The only drawing method this figure uses is drawLine(). The basic figure is a triangle. But rather than draw the full sized triangle, draw three half-sized triangles:

Write a method drawTriangle( int CenterX, int CenterY, int side ) that draws a triangle centered at (CenterX, CenterY) if side is small. Otherwise, it draws three triangles.

Click here to go back to the main menu.


End of Exercises