STUDENT-ORIENTED CODE SAMPLES
Teaching samples are usually not the best code. because they are designed to illustrate one point based on the students' current knowledge. For every snippet posted on a site, a better implementation is in the next chapter, in the next book, or on the next Web page. In fact, the best code samples on the Internet have been authored by developers to illustrate how to use modules within an API or SDK. Some of my favorites are included in the Links page.
The CPP Triangle Class
The triangle class, Triangle.cpp, contains a main paragraph that sends the lengths of the sides of a triangle to a function. The function validates that the 3 lengths describe a triangle, and indicates what kind of triangle it is. In the next program, students update this robust code sample to move the driver paragraph into a separate module.
|
Two-Dimensional Arrays in Java
![]()
This program is a rudimentary exploration of 2-dimensional arrays. It also introduces the concept of multiple windows, which is common for Java programs. It requires a class named DrawingPanel.java, which can be downloaded from the site named http://www.buildingjavaprograms.com/supplements.shtml. The site accompanies the textbook "Building Java Programs", which is the introductory programming textbook at UW Seattle.
After the students explore jFrame and jPanel objects, the ArayMax2 program can be written to extend those classes for a sleeker look. 2D Graphical Arrays in Java
![]()
This program explores multiple windows for Java programs; it was intended to be an extension of the araymax program, but the architecture imposed by the Java Virtual Machine meant a complete rewrite. The new program uses JFrame and JPanel objects to draw shapes in a 2-dimensional array on a screen.
The rewrite no longer requires the DrawPanel object; instead, each shape that can be drawn on the screen is its own class, and it coordinates with the JPanel object extension. |
Some presentations contain images that were included with purchased software.